#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, sz, signed(st.size()) - 1) a[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;}
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
5 ms |
208 KB |
Output is correct |
3 |
Correct |
9 ms |
208 KB |
Output is correct |
4 |
Correct |
10 ms |
208 KB |
Output is correct |
5 |
Correct |
5 ms |
208 KB |
Output is correct |
6 |
Correct |
11 ms |
208 KB |
Output is correct |
7 |
Correct |
8 ms |
328 KB |
Output is correct |
8 |
Correct |
11 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Incorrect |
9 ms |
328 KB |
Mismatch at position 1. Expected ), found ( |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
359 ms |
1104 KB |
Output is correct |
3 |
Correct |
739 ms |
1104 KB |
Output is correct |
4 |
Correct |
498 ms |
1104 KB |
Output is correct |
5 |
Correct |
687 ms |
1104 KB |
Output is correct |
6 |
Correct |
864 ms |
1104 KB |
Output is correct |
7 |
Correct |
766 ms |
1768 KB |
Output is correct |
8 |
Correct |
875 ms |
1104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Mismatch at position 1. Expected ), found ( |
2 |
Halted |
0 ms |
0 KB |
- |