이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
#define ll long long
using namespace std;
bool ask(ll num){
cout<<"? "<<num<<endl;
bool ans;
cin>>ans;
return ans;
}
int main(){
ll n;
cin>>n;
if(n==1){
cout<<"= 1"<<endl;
return 0;
}
if(n==2){
bool flag=ask(1);
flag=ask(2);
if(flag) cout<<"= 1"<<endl;
else cout<<"= 2"<<endl;
return 0;
}
ll L=0,R=0,last=(1+n-1)/2;
bool now=1;
while(last+1<n){
if(now) L+=(last+n)/2-last;
else R+=(last+n)/2-last;
now=!now;
last=(last+n)/2;
}
now=1;
L++;
R=n-R;
ll l=1,r=n;
bool ans=ask(L);
ans=ask(R);
last=(l+r-1)/2;
if(ans) r=(l+r-1)/2;
else l=(l+r-1)/2+1;
while(l<r){
ll mid=(l+r-1)>>1;
if(mid>last){
if(now){
L-=mid-last;
ans=ask(L);
}
else{
R+=mid-last;
ans=ask(R);
}
}
else{
if(now){
L+=last-mid;
ans=ask(L);
}
else{
R-=last-mid;
ans=ask(R);
}
}
now=!now;
last=mid;
if(ans) r=mid;
else l=mid+1;
}
cout<<"= "<<l<<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... |