//now if both x[1] and x[2] isn't 0 this is okay //if x[2] is 0? what will happen? //a[i] will be x[i]. How to ensure it? //we can ask(2,pos1,pos2) to check //if x[1] is 0: it is smaller than either a[pos1] or a[pos2] we can return [1,1] //if x[2] is 0: this returns a[pos1 or pos2] then we can return [2,pos1 or pos2] //otherwise we can return [pos1,pos2] //oops,there still can be x[1] is max and pos1 is zero
#include<bits/stdc++.h> usingnamespace std; #define ll long long #define mp make_pair #define reg register constint mxn=1e3+3; int n; int a[mxn],b[mxn]; inlineintask(int x,int y,int z){ cout<<"? "<<x<<' '<<y<<' '<<z<<endl; fflush(stdout); int rt;cin>>rt; return rt; } inlinevoidprint(int x,int y){ cout<<"! "<<x<<' '<<y<<endl; fflush(stdout); return; } inlinevoidsolve(){ cin>>n; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); int pos1=1; int allsame=1; int lst=-1; for(int i=3;i<=n;++i){ a[i]=ask(1,2,i); if(a[i]>a[pos1])pos1=i; if(lst==-1)lst=a[i]; else{ if(a[i]!=lst){ lst=a[i]; allsame=0; } } } int allsame2=1,lst2=-1; int pos2=1; for(int i=2;i<=n;++i){ if(i==pos1)continue; b[i]=ask(1,i,pos1); if(b[i]>=b[pos2])pos2=i; if(lst2==-1)lst2=b[i]; elseif(lst2!=b[i])allsame2=0; } if(pos2==2)++pos2; //当n较小的时候可能会出现pos2=2的阴间情况,需手动更改 if(pos2==pos1)++pos2;
if(allsame==1){//this can all be x[1]-x[2] int t=ask(1,pos1,pos2); if(t<lst){ print(1,2); return; } } //now if both x[1] and x[2] isn't 0 this is okay //if x[2] is 0? what will happen? //a[i] will be x[i]. How to ensure it? //we can ask(2,pos1,pos2) to check //if x[1] is 0: it is smaller than either a[pos1] or a[pos2] we can return [1,1] //if x[2] is 0: this returns a[pos1 or pos2] then we can return [2,pos1 or pos2] //otherwise we can return [pos1,pos2] //oops,there still can be x[1] is max and pos1 is zero if(allsame2==1){ print(1,pos1); return; } int t=ask(2,pos1,pos2); if((t<a[pos1] and t<=a[pos2]) or (t<=a[pos1] and t<a[pos2])){ print(1,2); return; } if(t==a[pos1]){ print(2,pos1); return; } if(t==a[pos2]){ print(2,pos2); return; }
print(pos1,pos2); return; } intmain(){ int T=1; cin>>T; for(;T--;)solve(); return0; }