#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
map<pii, int> mp;
int query(int l, int r) {
if(mp.count({ l, r })) return mp[{ l, r }];
cout << "? " << l << " " << r << endl;
int x;
cin >> x;
return mp[{ l, r }] = x;
}
signed main() {
int n;
cin >> n;
int l=2, r=n/2, ans=1;
while(l <= r) {
int mid = (l + r) / 2, ok = 0;
int len = 2 * mid + 1;
for(int i=1; i+len-1<=n; i++) {
if(query(i, i+len-1)) {
ok = 1;
break;
}
}
if(ok) ans = len, l = mid + 1;
else r = mid - 1;
}
l=1, r=n/2, ans2=0;
while(l <= r) {
int mid = (l + r) / 2, ok = 0;
int len = 2 * mid;
for(int i=1; i+len-1<=n; i++) {
if(query(i, i+len-1)) {
ok = 1;
break;
}
}
if(ok) ans = len, l = mid + 1;
else r = mid - 1;
}
cout << "! " << max(ans, ans2) << endl;
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:46:17: error: 'ans2' was not declared in this scope; did you mean 'ans'?
46 | l=1, r=n/2, ans2=0;
| ^~~~
| ans