https://codeforces.com/contest/1521/problem/C
思路:
开始找到最大值,令x=n-1,然后第一个max{min(),min()}的嵌套就可以O(n/2)找到最值
然后t=2,令x=1,然后O(n)扫一遍可以找到其他值。
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e4+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL ask(LL t,LL i,LL j,LL x){
cout<<"? "<<t<<" "<<i<<" "<<j<<" "<<x<<endl;
LL num;cin>>num;
cout.flush();
return num;
}
LL ans[maxn];
int main(void){
LL T;cin>>T;
while(T--){
LL n;cin>>n;
for(LL i=0;i<n+10;i++) ans[i]=0;
LL mxpos=n;
for(LL i=1;i+1<=n;i+=2){
LL num=ask(1,i,i+1,n-1);
if(num==n){
mxpos=i+1;break;
}
if(num==n-1){
num=ask(1,i+1,i,n-1);
if(num==n){
mxpos=i;break;
}
}
}
ans[mxpos]=n;
for(LL i=1;i<=n;i++){
if(i==mxpos) continue;
LL num=ask(2,i,mxpos,1);
ans[i]=num;
}
cout<<"! ";
for(LL i=1;i<=n;i++){
cout<<ans[i]<<" ";
}
cout<<endl;
cout.flush();
}
return 0;
}