#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 int long long int
#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() {
ios::sync_with_stdio(false), cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> a(n + 1, 0), st;
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();
};
rep(i, 1, n) {
if(!st.size()) st.push_back(i);
else {
int cur = st.back();
if(query(cur, i)) {
st.pop_back();
a[i] = 1;
}
else st.push_back(i);
}
}
assert(st.size() % 2 == 0);
int sz = st.size() / 2;
rep(i, 0, sz - 1) a[st[i]] = 1;
report();
return 0;
}
Compilation message
zagrade.cpp:17:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
17 | void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L)==R], ++L;}
| ^~~~
zagrade.cpp:17:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
17 | void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L)==R], ++L;}
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
4 ms |
208 KB |
Output is correct |
3 |
Correct |
9 ms |
256 KB |
Output is correct |
4 |
Correct |
7 ms |
208 KB |
Output is correct |
5 |
Correct |
9 ms |
208 KB |
Output is correct |
6 |
Correct |
7 ms |
208 KB |
Output is correct |
7 |
Correct |
11 ms |
208 KB |
Output is correct |
8 |
Correct |
9 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
8 ms |
332 KB |
Output is correct |
3 |
Correct |
10 ms |
208 KB |
Output is correct |
4 |
Correct |
10 ms |
336 KB |
Output is correct |
5 |
Correct |
10 ms |
208 KB |
Output is correct |
6 |
Correct |
9 ms |
328 KB |
Output is correct |
7 |
Correct |
11 ms |
336 KB |
Output is correct |
8 |
Correct |
6 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
349 ms |
1104 KB |
Output is correct |
3 |
Correct |
799 ms |
1104 KB |
Output is correct |
4 |
Correct |
774 ms |
1104 KB |
Output is correct |
5 |
Correct |
668 ms |
1104 KB |
Output is correct |
6 |
Correct |
553 ms |
1152 KB |
Output is correct |
7 |
Correct |
780 ms |
1736 KB |
Output is correct |
8 |
Correct |
465 ms |
1104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
476 ms |
2164 KB |
Output is correct |
3 |
Correct |
853 ms |
1476 KB |
Output is correct |
4 |
Correct |
757 ms |
1724 KB |
Output is correct |
5 |
Correct |
842 ms |
1480 KB |
Output is correct |
6 |
Correct |
731 ms |
1744 KB |
Output is correct |
7 |
Correct |
775 ms |
1480 KB |
Output is correct |
8 |
Correct |
797 ms |
1128 KB |
Output is correct |