#define wiwihorz
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define ceil(a, b) ((a + b - 1) / (b))
#define all(x) x.begin(), x.end()
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())
#define INF 1000000000000000000
#define MOD 1000000007
#define eps (1e-9)
using namespace std;
#ifdef wiwihorz
#define print(a...)cerr<<"Line "<<__LINE__<<":",kout("["+string(#a)+"] = ", a)
void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L)==R], ++L;}
void kout(){cerr<< endl;}
template<class T1,class ... T2>void kout(T1 a,T2 ... e){cerr<<a<<" ",kout(e...);}
#else
#define print(...) 0
#define vprint(...) 0
#endif
signed main() {
int n, q;
cin >> n >> q;
vector<int> a(n + 1, 0), v(n + 1, 0);
auto query = [&](int L, int R) {
cout << "? " << L << " " << R << "\n";
cout.flush();
int x; cin >> x;
return x;
};
auto report = [&]() {
cout << "! ";
rep(i, 1, n) cout << (a[i] ? ")" : "(");
cout << "\n";
cout.flush();
};
a[n] = 1;
map<int, int> pos;
pos[0] = 0, pos[1] = 1;
v[1] = 1;
rep(i, 2, n - 1) {
int pre = v[i - 1], x = 0;
if(pos.find(pre - 1) != pos.end())
x = query(pos[pre - 1] + 1, i);
a[i] = x;
v[i] = pre + (a[i] ? -1 : 1);
pos[v[i]] = i;
}
report();
return 0;
}
Compilation message
zagrade.cpp:16:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
16 | void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L)==R], ++L;}
| ^~~~
zagrade.cpp:16:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
16 | void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L)==R], ++L;}
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
208 KB |
Output is correct |
3 |
Correct |
5 ms |
208 KB |
Output is correct |
4 |
Correct |
11 ms |
208 KB |
Output is correct |
5 |
Correct |
7 ms |
208 KB |
Output is correct |
6 |
Correct |
10 ms |
336 KB |
Output is correct |
7 |
Correct |
8 ms |
208 KB |
Output is correct |
8 |
Correct |
8 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Mismatch at position 1. Expected ), found ( |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
312 ms |
1072 KB |
Output is correct |
3 |
Correct |
710 ms |
1076 KB |
Output is correct |
4 |
Correct |
771 ms |
1084 KB |
Output is correct |
5 |
Correct |
589 ms |
1080 KB |
Output is correct |
6 |
Correct |
694 ms |
1088 KB |
Output is correct |
7 |
Correct |
815 ms |
3428 KB |
Output is correct |
8 |
Correct |
689 ms |
1088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Mismatch at position 1. Expected ), found ( |
2 |
Halted |
0 ms |
0 KB |
- |