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>
using namespace std;
#define int long long
int l, r, ans;
void query(int x)
{
cout<<"? "<<x<<endl;
cin>>ans;
}
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin>>n;
l=n/2, r=l;
query(l);
int t=1;
for(int i=62; i>=0; i--)
{
if(t%2==1&&(1LL<<i)+r<=n)
{
r+=(1LL<<i);
query(r);
if(ans==1)
{
l+=min(n-l, 1LL<<i);
}
t++;
}
else if((t%2==0)&&(1LL<<i)<l)
{
l-=(1LL<<i);
query(l);
if(ans==1)
{
r-=min(r, (1LL<<i));
}
t++;
}
}
cout<<"! "<<abs(l-r)+1<<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... |