QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#396533 | #1813. Joy with Permutations | Network_Error | TL | 0ms | 0kb | C++14 | 1.5kb | 2024-04-22 21:11:14 | 2024-04-22 21:11:15 |
answer
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii tuple<int,int,int>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define deb(var) cerr<<#var<<'='<<(var)<<"; "
#define int long long
int n,ans[100010];
int ask(int x,int y,int z){
printf("? 1 %d %d %d",x,y,z);
cout<<endl;fflush(stdout);
int o;cin>>o;return o;
}
bool lt(int x,int y){
printf("? 2 %d %d",x,y);
cout<<endl;fflush(stdout);
int o;cin>>o;return o==x;
}
void work(){
cin>>n;
int t1,t2,t3,t4;
tie(t1,t2,t3,t4)=mt(ask(1,2,3),ask(1,2,4),ask(1,3,4),ask(2,3,4));
int a,b,c,d,l=min({t1,t2,t3,t4}),r=max({t1,t2,t3,t4});
if(t1==t2&&t2==l)a=1,b=2,c=3,d=4;
else if(t1==t3&&t3==l)a=1,b=3,c=2,d=4;
else if(t1==t4&&t4==l)a=2,b=3,c=1,d=4;
else if(t2==t3&&t3==l)a=1,b=4,c=2,d=3;
else if(t2==t4&&t4==l)a=2,b=4,c=1,d=3;
else if(t3==t4&&t4==l)a=3,b=4,c=1,d=2;
//----------------------------------------------------------------
for(int i=5;i<=n;i++){
int O=ask(a,c,i);
if(l<O&&O<r)ans[i]=O;
else if(O<l){
ans[b]=l;b=i,l=O;
}else if(O>r){
ans[d]=r;d=i,r=O;
}else if(O==l){
ans[a]=O;a=i,l=ask(a,b,c);
}else if(O==r){
ans[c]=O;c=i;r=ask(c,d,a);
}
}
#define p ans
if(lt(a,b))p[a]=1,p[b]=2;else p[a]=2,p[b]=1;
if(lt(c,d))p[c]=n-1,p[d]=n;else p[c]=n,p[d]=n-1;
cout<<"! ";for(int i=1;i<=n;i++)cout<<ans[i]<<' ';cout<<endl;
}
signed main(){
ios::sync_with_stdio(0),
cin.tie(0),cout.tie(0);
int T=1;while(T--)work();return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
5
output:
? 1 2 3 4