๐Ÿ“ฆ ved015 / Codeforces-solution

๐Ÿ“„ e.cpp ยท 57 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);

int query(int l, int r) {
    cout << "? " << l << " " << r << endl;
    fflush(stdout);
    int ret;
    cin >> ret;
    return ret;
}

void solve() {
    int n;
    cin >> n;
    vi a(n);


    for (int i = 2; i <= n; i++) {
        a[i - 1] = query(1, i);
    }

    if (a[n - 1] == 0) {
        cout << "! IMPOSSIBLE" << endl;
        return;
    }

    string s(n, '0');
    int i = 0;

    while (a[i] == 0) i++;


    for (int j = 0; j < i - a[i]; j++) {
        s[j] = '1';
    }
    for (int j = i; j < n; j++) {
        s[j] = (a[j] > a[j - 1]) ? '1' : '0';
    }

    cout << "! " << s << endl;
    fflush(stdout);
}

int main() {
    fastio();
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}