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"
using namespace std;
#define int long long
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
if(p==0) return 1 % MOD;
int r = bm(b, p >> 1);
if(p&1) return (((r*r) % MOD) * b) % MOD;
return (r*r) % MOD;
}
int inv(int b) {
return bm(b, MOD-2);
}
int fastlog(int x) {
return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void printcase(int i) { cout << "Case #" << i << ": "; }
int isp(int l, int r) {
cout << "? " << l << ' ' << r << endl;
int x; cin >> x; return x;
}
void solve(int tc) {
int n;
cin >> n;
deque<int>dq;
int ans=0;
for(int i=1;i<=n;i++){
while(dq.size()) {
int l = dq.back() / 2, r = (dq.back() + 1) / 2;
l -= (i - r);
r = i;
if(l >= 1 && isp(l, r)) {
break;
}
else {
dq.pop_back();
}
}
if(i > 1 && isp(i-1, i)) dq.push_front(2*i-1);
dq.push_front(2*i);
int l = dq.back() / 2, r = (dq.back() + 1) / 2;
l -= (i - r);
r = i;
ans = max(ans, r-l+1);
}
cout << "! " << ans << endl;
}
int32_t main() {
//ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
// 勿忘初衷
# | 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... |