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>
#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;
}
int get1(int p, int d, int n) {
if(p - d < 1 || p + d > n) return 0;
return query(p - d, p + d);
}
int get2(int p, int d, int n) {
if(p - d + 1 < 1 || p + d > n) return 0;
return query(p - d + 1, p + d);
}
signed main() {
int n, ans1=0, ans2=0;
cin >> n;
for(int i=1; i<=n; i++)
while(get1(i, ans1+1, n)) ans1++;
for(int i=1; i+1<=n; i++)
while(get2(i, ans2+1, n)) ans2++;
cout << "! " << max(2 * ans1 + 1, 2 * ans2) << endl;
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... |