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;
typedef long long ll;
int main() {
int n; cin>>n;
int ans1=1;
for (int i=1; i<=n; i++) {
if (ans1==n) break;
int l=i-(ans1+2)/2,r=i+(ans1+2)/2;
if (l<1||r>n) continue;
cout<<"? "<<l<<" "<<r<<endl;
cout.flush();
int a; cin>>a;
if (a) {
while (true) {
ans1=max(ans1,r-l+1);
l--; r++;
if (l<1||r>n) break;
cout<<"? "<<l<<" "<<r<<endl;
cout.flush();
cin>>a;
if (!a) break;
}
}
}
int ans2=0;
for (int i=1; i<=n; i++) {
if (ans1==n||ans2==n) break;
int l=i-(ans2+2)/2+1,r=i+(ans2+2)/2;
if (l<1||r>n) continue;
cout<<"? "<<l<<" "<<r<<endl;
cout.flush();
int a; cin>>a;
if (a) {
while (true) {
ans2=max(ans2,r-l+1);
l--; r++;
if (l<1||r>n) break;
cout<<"? "<<l<<" "<<r<<endl;
cout.flush();
cin>>a;
if (!a) break;
}
}
}
cout<<"! "<<max(ans1,ans2)<<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... |