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;
int query(int le, int ri)
{
if((ri-le+1)%2==1)
return 0;
cout<<"? "<<le<<" "<<ri<<endl;
int aux;
cin>>aux;
return aux;
}
char rez[100005];
signed main()
{
cin>>n>>q;
int cnt=n/2;
deque<int> dq;
for(int i=1;i<=n;i++)
{
dq.push_back(i);
if((int)dq.size()>=2 && query(dq[(int)dq.size()-2],dq.back()))
{
rez[dq[(int)dq.size()-2]] = '(';
rez[dq[(int)dq.size()-1]] = ')';
dq.pop_back();
dq.pop_back();
cnt--;
}
}
for(int i=0;i<cnt;i++)
{
rez[dq[i]]=')';
rez[dq[(int)dq.size()-i-1]]='(';
}
cout<<"! ";
for(int i=1;i<=n;i++)
cout<<rez[i];
cout<<endl;
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... |