This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Author : FatihCihan
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
int n;
int ask(int l , int r){
if(l < 1 or r > n){
while(true){
37;
}
}
cout << "? " << l << " " << r << endl;
int x;
cin >> x;
return x;
}
void answer(int x){
cout << "! " << x << endl;
exit(0);
}
void solve(){
cin >> n;
int r = 1 , ans = 1;
for(int i = 1;i<=n;i++){
r = max(r , i);
while((r+1) <= n and (i-(r-i)-1) >= 1 and ask(i-(r-i)-1 , r+1)){
r++;
}
ans = max(ans , 2 * (r - i) + 1);
}
r = 0;
for(int i = 1;i<n;i++){
if(r <= i){
if(ask(i,i+1))r = i+1;
else continue;
}
while((r+1) <= n and (i-(r-i)) >= 1 and ask(i-(r-i) , r+1)){
r++;
}
if(r > i){
ans = max(ans , 2 * (r - i));
}
}
answer(ans);
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int testcase = 1;//cin >> testcase;
while(testcase--)solve();
cerr << 1000.0 * clock() / CLOCKS_PER_SEC << " ms" << endl;
}
Compilation message (stderr)
Main.cpp: In function 'int ask(int, int)':
Main.cpp:10:4: warning: statement has no effect [-Wunused-value]
10 | 37;
| ^~
# | 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... |