#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()
ll ask(ll x) {
cout << "? " << x << endl;
ll val;
cin >> val;
return val;
}
int main() {
ll n;
cin >> n;
ll l = 0, r = n;
ll pos = 1;
vector<ll> v;
while (l + 1 < r) {
v.push_back((l + r) / 2);
l = (l + r) / 2;
}
reverse(all(v));
for (auto x : v) {
if (pos + x <= n) pos += x;
else pos -= x;
}
ask(pos);
unordered_set<ll> used;
l = 0, r = n;
while (l + 1 < r) {
ll mid = (l + r) / 2;
if (pos + mid <= n && !used.count(pos + mid)) pos += mid;
else pos -= mid;
used.insert(pos);
ll x = ask(pos);
if (x) r = mid;
else l = mid;
}
cout << "= " << r << endl;
}
# | 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... |