This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n, q;
inline bool query(int l, int r) {
cout << "? " << l << ' ' << r << endl;
bool res;
cin >> res;
return res;
}
int main() {
cin >> n >> q;
set<int> pos;
for(int i = 1;i <= n;i ++) {
pos.insert(i);
}
char ans[n+1];
ans[n] = '\0';
auto it = pos.begin();
while(it != (--pos.end())) {
auto crr = (it++);
if(query(*crr, *it)) {
ans[(*crr) - 1] = '(';
ans[(*it) - 1] = ')';
int values = -1;
set<int>::iterator ptr;
if(crr != pos.begin()) {
ptr = crr;
ptr --;
values = *ptr;
} else {
if(it != (--pos.end())) {
ptr = it;
ptr ++;
values = *ptr;
}
}
pos.erase(crr);
pos.erase(it);
if(values != -1) {
it = pos.find(values);
}
}
if((int)pos.size() == 0) {
break;
}
}
if((int)pos.size()) {
it = pos.begin();
for(int rep = 0;rep < (int)pos.size() / 2;rep ++) {
ans[(*it)-1] = ')';
it ++;
}
while(it != pos.end()) {
ans[(*it)-1] = '(';
it ++;
}
}
string out = ans;
cout << "! " << out << '\n';
return 0;
}
# | 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... |