// #include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <set>
#include <deque>
#include <numeric>
#include <stack>
#include <chrono>
using namespace std;
void fast_io(){
// freopen("", "r", stdin);
// freopen("", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(); cout.tie();
cout << setprecision(9);
}
#define int long long
// #define endl '\n'
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
int n;
bool query(int l, int r){
cout << "? " << l << ' ' << r << endl;
int x; cin >> x;
return x;
}
void solve() {
int ans = 1; cin >> n;
for (int i = 1; i <= n; i++){
if (ans % 2 == 0){
int l = i - ans / 2, r = i + ans / 2;
while (l > 0 && r <= n){
int x = query(l, r);
if (x) ans = max(ans, r - l + 1);
else break;
l--, r++;
}
}
else {
int l = i - (ans + 1) / 2, r = i + (ans + 1) / 2;
while (l > 0 && r <= n){
int x = query(l, r);
if (x) ans = max(ans, r - l + 1);
else break;
l--, r++;
}
}
int l = i - ans / 2, r = i + ans / 2 + 1;
while (l > 0 && r <= n){
int x = query(l, r);
if (x) ans = max(ans, r - l + 1);
else break;
l--, r++;
}
}
cout << "! " << ans << endl;
return;
}
signed main() {
fast_io();
srand(chrono::steady_clock::now().time_since_epoch().count());
int tc = 1;
// cin >> tc;
while (tc--) solve();
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... |