#include <bits/stdc++.h>
using namespace std;
#define int long long
#define nl endl
#define hehe ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL) ;
// const int mod = 998244353;
const int mod = 1e9+7;
const int M = 2e5+5;
int gas(int l, int r){
cout << "? " << l << ' ' << r << nl;
int x; cin >> x;
return x;
}
void solve(){
int n; cin >> n;
int ans = 1;
int r = 1;
// ganjil
//
for(int i = 1; i<=n; i++){
if(r < i) r = i;
while(r < n){
int l = 2*i-r-1;
if(l < 1)break;
if(gas(l,r+1) == 1){
r++;
}
else break;
}
ans = max(ans, 2*(r-i)+1);
}
r = 1;
for(int i = 1; i<=n-1; i++){
if(r < i) r = i;
while(r<n){
int l = 2*i-r;
if(l < 1)break;
if(gas(l,r+1)==1){
r++;
}
else break;
}
ans = max(ans,2*r-i);
}
cout << "! " << ans << nl;
}
signed main(){
hehe
int t; cin >> t;
//int t = 1;
while(t--){
solve();
}
}
# | 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... |