#include <bits/stdc++.h>
#define int long long
using namespace std;
int ask(int l, int r) {
cout << "? " << l << " " << r;
cout << endl;
int x;
cin >> x;
return x;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
stack<int> s;
s.push(1);
vector<int> a(n + 1, - 1);
a[1] = 1;
for(int i = 2; i <= n; i++) {
if(!s.size()) {
a[i] = 1;
s.push(i);
continue;
}
if(ask(s.top(), i)) {
a[i] = 0;
s.pop();
}
else {
a[i] = 1;
s.push(i);
}
}
cout << "! ";
for(int i = 1; i <= n; i++) {
if(a[i]) {
cout << "(";
}
else {
cout << ")";
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |