solution
看到 且 为整数,刻在 DNA 里的反应告诉我们可以二分,所以我们考虑如何二分。
首先对于 这个数字因为 次方二分出来需要 次,那么我们就需要在 次之内判断一个可信任的区间,即判断一个区间一定有 ,或一定没有 。
所以我们肯定考虑以 作为分界点,显然的对于两个长度同为 的区间来说,若两个区间系统返回的答案不同时,两区间中必内必有一个内有 ,因此可以在两次内判断出 内有没有 ,由于只有一个 所以也可以得到 的 的个数。
但是我们会发现,现在仍不能二分,因为我们虽然知道了 的位置,但是并不知道k的大小不能确定二分的判断条件是系统返回 还是 ,所以我们需要确定 的大小,显然我们只能在 次询问之内判断出来 与 的关系,由于前面我们知道了 的位置,且刚刚好是以 的长度的,所以我们考虑询问有 的那个区间内若返回 则 否则大于 。
然后我们就可以分四类进行讨论即可。
code
//Author:Kevin Z K Y
#include <bits/stdc++.h>
#define up(a,b,c) for(int (a)=(b);(a)<=(c);(a)++)
#define dn(a,b,c) for(int (a)=(b);(a)>=(c);(a)--)
#define fst first
#define sed second
using namespace std;
using ull = unsigned long long ;using ui = unsigned int ;
using ll = long long ;using hint = __int128 ;
using pii = pair<int,int> ;using pll = pair<ll,ll> ;
using vi = vector<int> ;using vl = vector<ll> ;
using vpi = vector<pii> ;using vpl = vector<pll> ;
using db = double ;namespace mystl{
#define gc() getchar()
ll qpow(ll a,ll b,const ll&p){if (a==0ll) return 0ll; ll c=1ll;
while(b) { if(b & 1) c=a*c%p; a=a*a%p; b>>=1; } return c; }
template<typename T>void read(T&x) {x=0; bool f=false; char ch;
ch = gc(); while(ch<'0'||ch>'9') f |= ( ch=='-') , ch=gc();
while(ch>='0'&&ch<='9') x=x*10+ch-'0' , ch=gc(); x=f?-x:x;}
template<typename T>void write(T x){char s[40];short d=0;T y=x;
if(x<0) putchar('-'),y=-y;if(x==0){ putchar('0'); return; }
while(y){s[++d]=y%10+'0';y/=10;}while(d>0)putchar(s[d--]);}
template<typename T>void wris(T x,char c){write(x);putchar(c);}
}using namespace mystl;
namespace my{
void solve(){
int n;cin>>n;
cout<<"? "<<1<<' '<<n/4<<'\n';
fflush(stdout);
int ll;cin>>ll;
cout<<"? "<<n/4+1<<' '<<n/2<<'\n';
fflush(stdout);
int lr;cin>>lr;
if(ll==lr)cout<<"? "<<n/2+1<<' '<<n<<'\n';
else cout<<"? "<<1<<' '<<n/2<<'\n';
fflush(stdout);
int P;cin>>P;
int best;
if(ll==lr){
if(P){
// cout<<"----------------1\n";
int l=1,r=n/2;best=n/2;while(l<=r){
int mid=l+(r-l)/2;
cout<<"? "<<mid<<' '<<n<<'\n';fflush(stdout);
int Flag;cin>>Flag;
if(Flag==1)best=n-mid+1,r=mid-1;
else l=mid+1;
}
}else {
// cout<<"----------------2\n";
int l=1,r=n/2;best=1;while(l<=r){
int mid=l+(r-l)/2;
cout<<"? "<<1<<' '<<mid<<'\n';fflush(stdout);
int Flag;cin>>Flag;
if(Flag==0)best=mid,l=mid+1;
else r=mid-1;
}
}
}else {
if(P){
// cout<<"----------------3\n";
int l=n/2+1,r=n;best=n/2;while(l<=r){
int mid=l+(r-l)/2;
cout<<"? "<<1<<' '<<mid<<'\n';fflush(stdout);
int Flag;cin>>Flag;
if(Flag==1)best=mid,l=mid+1;
else r=mid-1;
}
}else {
// cout<<"----------------4\n";
int l=n/2+1,r=n;best=1;while(l<=r){
int mid=l+(r-l)/2;
cout<<"? "<<mid<<' '<<n<<'\n';fflush(stdout);
int Flag;cin>>Flag;
if(Flag==0)best=n-mid+1,r=mid-1;
else l=mid+1;
}
}
}cout<<"! "<<best+1<<'\n';fflush(stdout);
}
}
int main(){
// freopen("","r",stdin);
// freopen("","w",stdout);
// ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int _=1;cin>>_;while(_--)my::solve();return 0;
}