/**
* author: wxhtzdy
* created: 09.08.2022 16:41:55
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int na, nb;
cin >> na >> nb;
auto Ask = [&](int i, int j) {
cout << "cmp " << i << " " << j << endl;
int x;
cin >> x;
return x;
};
vector<int> at(na);
for (int i = 0; i < na; i++) {
int low = 1, high = nb;
while (low <= high) {
int mid = low + high >> 1;
if (Ask(i + 1, na + mid) > 0) {
at[i] = mid;
low = mid + 1;
} else {
high = mid - 1;
}
}
}
auto Reverse = [&](int pos, int la, int lb) {
assert(la >= 1 && lb >= 1);
cout << "reverse " << pos << " " << pos + la + lb - 1 << endl;
if (la > 1) {
cout << "reverse " << pos + lb << " " << pos + la + lb - 1 << endl;
}
if (lb > 1) {
cout << "reverse " << pos << " " << pos + lb - 1 << endl;
}
};
int ptr = 0;
for (int i = 0; i < na; i++) {
if (ptr < at[i]) {
Reverse(i + 1 + ptr, na - i, at[i] - ptr);
ptr = at[i];
}
}
cout << "end" << endl;
return 0;
}
Compilation message
nizovi.cpp: In function 'int main()':
nizovi.cpp:24:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
24 | int mid = low + high >> 1;
| ~~~~^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
2 ms |
208 KB |
Output is correct |
3 |
Correct |
3 ms |
208 KB |
Output is correct |
4 |
Correct |
36 ms |
300 KB |
Output is correct |
5 |
Correct |
53 ms |
292 KB |
Output is correct |
6 |
Correct |
43 ms |
208 KB |
Output is correct |
7 |
Correct |
166 ms |
308 KB |
Output is correct |
8 |
Correct |
192 ms |
328 KB |
Output is correct |
9 |
Correct |
113 ms |
336 KB |
Output is correct |
10 |
Correct |
192 ms |
296 KB |
Output is correct |