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 pb push_back
#define int long long
using namespace std;
const int inf = 1e15 + 10;
const int N = 3e5 + 5;
bool query(int l, int r){
cout<<"? "<<l<<" "<<r<<endl;
cout.flush();
bool pal;
cin>>pal;
return pal;
}
int32_t main(){
int n;
cin>>n;
int oddmx = 1, evenmx = 0;
for(int i = 1; i <= n; i++){
int st = oddmx + 2;
for(int len = st; len <= n; len += 2){
int l = i - (len - 1)/2, r = i + (len - 1)/2;
if(l < 1 || r > n) break;
bool pal = query(l, r);
if(!pal) break;
oddmx = len;
}
}
for(int i = 1; i <= n; i++){
int st = max(oddmx + 1, evenmx + 2);
for(int len = st; len <= n; len += 2){
int l = i - len/2 + 1, r = i + len/2;
if(l < 1 || r > n) break;
bool pal = query(l, r);
if(!pal) break;
evenmx = len;
}
}
int ans = max(oddmx, evenmx);
cout<<"! "<<ans<<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... |