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;
const int nx=1e5+5;
int n, res[nx], x, q;
int query(int l, int r)
{
cout<<"? "<<l<<' '<<r<<'\n';
fflush(stdout);
cin>>x;
return x;
}
void fillres(int l, int r)
{
int md=(l+r)/2;
for (int i=l; i<=md; i++) res[i]=1;
}
void solve2(int l, int r)
{
if (r<=l) return;
int lst=l;
for (int i=l+1; i<r; i+=2) if (query(l, i)) fillres(lst, i), lst=i+1;
if (lst<r) fillres(lst, r);
}
void solve1(int l, int r)
{
res[l]=1;
for (int i=l+1; i<r; i+=2) if (query(l, i)) return solve2(l+1, i-1), solve1(i+1, r), void();
solve2(l+1, r-1);
}
int main()
{
cin>>n>>q;
solve1(1, n);
cout<<"! ";
for (int i=1; i<=n;i ++) cout<<(res[i]?'(':')');
}
/*
12
()(()())(())
*/
# | 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... |