This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define int long long
using namespace std;
int query(int x){
cout <<"? "<<x<<endl;
int ans;
cin>>ans;
return ans;
}
signed main(){
//setIO("closing");
int n;
cin>>n;
int l=0;
int r=n;
int pos=1;
vector<int> tab;
while(r-l>1){
tab.pb((r+l)/2);
l=(r+l)/2;
}
reverse(tab.begin(), tab.end());
for(auto u:tab)
pos+=(pos+u <= n ? u : -u);
map<int,bool> vis;
l=0;r=n;
vis[pos]=true;
query(pos);
while(r-l>1){
int mid=(r+l)/2;
if(pos+mid<=n&&!vis[pos+mid]){
pos+=mid;
}else pos-=mid;
vis[pos]=1;
if(query(pos)) 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... |