#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define F first
#define S second
#define sz(x) int(x.size())
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
cin >> n;
int l=0, r=n/2+1, m;
while(l+1<r) {
m=(l+r)/2;
int L=m*2;
if(L>n) {
r=m;
continue;
}
int ok=0;
for(int i=1; i<=n-L+1; i++) {
cout << "? " << i << ' ' << i+L-1 << '\n';
cout.flush();
int x;
cin >> x;
if(x) {
ok=1;
break;
}
}
if(ok) {
l=m;
}
else {
r=m;
}
}
int out=2*l;
l=0, r=n/2+1;
while(l+1<r) {
m=(l+r)/2;
int L=m*2+1;
if(L>n) {
r=m;
continue;
}
int ok=0;
for(int i=1; i<=n-L+1; i++) {
cout << "? " << i << ' ' << i+L-1 << '\n';
cout.flush();
int x;
cin >> x;
if(x) {
ok=1;
break;
}
}
if(ok) {
l=m;
}
else {
r=m;
}
}
out=max(out, 2*l+1);
cout << "! " << out << '\n';
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... |