#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)
{
//cout<<"Debug "<<l<<' '<<r<<'\n';
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;
if (l+1==r) return res[l]=1, void();
int lst=l;
for (int i=l+1; i<r; i+=2) if (query(l, i)) fillres(lst, i), lst=i+1;
fillres(lst, r);
}
void solve1(int l, int r)
{
if (r==l+1) return res[l]=1, void();
for (int i=l+1; i<r; i+=2) if (query(l, i)) return res[l]=1, solve2(l+1, i-1), solve1(i+1, r), void();
res[l]=1;
solve2(l+1, r-1);
}
int main()
{
cin>>n>>q;
solve1(1, n);
cout<<"! ";
for (int i=1; i<=n;i ++) cout<<(res[i]?'(':')');
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Incorrect |
5 ms |
344 KB |
Mismatch at position 9. Expected ), found ( |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Mismatch at position 1. Expected ), found ( |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
255 ms |
1148 KB |
Output is correct |
3 |
Incorrect |
497 ms |
852 KB |
Mismatch at position 15. Expected ), found ( |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Mismatch at position 1. Expected ), found ( |
2 |
Halted |
0 ms |
0 KB |
- |