#include <bits/stdc++.h>
using namespace std;
// #define endl "\n"
#define pb push_back
#define int long long
#define fi first
#define se second
const int N = 3e5 + 5, M = 1e9 + 7, LG = 20;
int n , A[N] , x;
bool p = 0;
bool ch(int mid , bool o){
if (!o){
for (int i = 1 ; i<=n ; i++){
if ((i-mid) >= 1 && (i+mid) <= n){
cout << "? " << i-mid << " " << i+mid << endl;
cin >> x;
if (x){
return 1;
}
}
}
return 0;
}else{
for (int i = 1 ; i<n ; i++){
if (!p){
cout << "? " << i << ' ' << i+1 << endl;
cin >> x;
if (x){
p = 1;
}
}
if ((i-mid) >= 1 && (i+mid+1) <= n && p){
cout << "? " << i-mid << " " << i+mid+1 << endl;
cin >> x;
if (x){
return 1;
}
}
}
return 0;
}
}
void solve(){
cin >> n;
int l=0 , r = (n/2) + 1;
while(l+1 < r){
int mid = (l+r)>>1;
if (ch(mid,0)){
l = mid;
}else{
r = mid;
}
}
int ans = 2*l+1;
l=0 , r = (n/2) + 1;
while(l+1 < r){
int mid = (l+r)>>1;
if (ch(mid,1)){
l = mid;
}else{
r = mid;
}
}
if (p) ans = max(ans , 2*l+2);
cout <<"! "<< ans << endl;
}
signed main(){
// freopen("" , "r" , stdin);
// freopen("" , "w" , stdout);
// cout << setprecision(30);
// ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int ts = 1;
// cin >> ts;
while(ts--){
solve();
}
}
| # | 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... |