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: chowgz
* created: 13/04/2021 20:13:22
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >> tt;
while (tt--) {
long long n;
cin >> n;
long long l = 1, r = n - 1, m = (l + r) / 2;
stack<long long> s;
while (m != n - 1) {
m = (l + r) / 2;
s.push(m);
l = m + 1;
}
long long cur = n;
bool up = false;
while (!s.empty()) {
cur += up ? s.top() : -s.top();
up = !up;
s.pop();
}
bool yes;
auto ask = [&](long long x) {
cur += up ? x : -x;
up = !up;
cout << "? " << cur << endl;
cout.flush();
cin >> yes;
};
cout << "? " << cur << endl;
cout.flush();
cin >> yes;
l = 1;
r = n - 1;
m = (l + r) / 2;
long long ans = n;
while (l <= r) {
ask(m);
if (yes) {
ans = m;
r = m - 1;
} else {
l = m + 1;
}
m = (l + r) / 2;
}
cout << "= " << ans << endl;
cout.flush();
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |