This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author: wxhtzdy
* created: 05.07.2022 14:44:38
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
auto Ask = [&](int l, int r) {
cout << "? " << l + 1 << " " << r + 1 << endl;
int x;
cin >> x;
return x;
};
int ans = 1;
for (int i = 1; i < n; i++) {
while (true) {
int l = i - (ans + 1) / 2;
int r = i + (ans + 1) / 2;
if (l < 0 || r >= n || !Ask(l, r)) {
break;
}
ans = r - l + 1;
}
}
for (int i = 0; i + 1 < n; i++) {
while (true) {
int l = i - (ans % 2 == 1 ? (ans - 1) / 2 : ans / 2);
int r = i + 1 + (ans % 2 == 1 ? (ans - 1) / 2 : ans / 2);
if (l < 0 || r >= n || !Ask(l, r)) {
break;
}
ans = r - l + 1;
}
}
cout << "! " << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |