C. Nastia and a Hidden Permutation(构造)

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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值