Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
34091 LYLAKIOI 【S】T2 C++ 解答错误 0 227 MS 1220 KB 2173 2024-11-03 14:53:15

Tests(0/20):


#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define p1 first #define p2 second #define m_p make_pair #define p_b push_back typedef long long ll; using namespace std; const int maxn=2e6+10; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; } int n,P[maxn],loc[maxn]; struct nd { int a,b,c; nd(int _a,int _b,int _c){a=_a,b=_b,c=_c;} }; vector<nd>vec; void op(int a,int b,int c){ vec.p_b(nd(a,b,c)); if(P[a]>P[c])swap(P[a],P[b]),swap(loc[P[a]],loc[P[b]]); else swap(P[b],P[c]),swap(loc[P[b]],loc[P[c]]); } void sol(){ up(i,2,n)if(P[i]!=i)if(loc[i]<i)op(1,loc[i],i);else op(1,i,loc[i]); } void calc(){ vec.clear(); if(loc[1]==1){sol();return;} int pos=-1; up(i,loc[1]+1,n)if(P[i]<P[1])pos=i; if(pos!=-1){ op(1,loc[1],pos);sol();return; }if(P[1]>=3){ up(i,2,loc[1]-1)if(P[i]<P[1]){ op(1,i,n);break; }op(1,loc[1],n);sol();return; } if(P[2]==1){ up(i,3,n-1)if(P[i]>P[i+1]){ op(1,2,i),op(1,2,i),op(1,2,i+1); sol();return; } op(1,2,3),op(1,2,3),op(1,2,4),op(1,3,4),op(1,2,4); return; } op(1,2,loc[1]); up(i,2,loc[1]-1)if(P[i]<P[1]){ op(1,i,n);break; }op(1,loc[1],n);sol();return; } void slv(){ n=read();int L=read();up(i,1,n)P[i]=read(),loc[P[i]]=i; bool ok=1; up(i,1,n)if(P[i]!=i)ok=0; if(ok){printf("0\n");return;} if(n<=3){printf("-1\n");return;} if(loc[1]==n){printf("-1\n");return;} calc(); if(int(vec.size())>L){printf("-1\n");return;} printf("%d\n",(int)vec.size()); for(auto it:vec){ int a=it.a,b=it.b,c=it.c; printf("%d %d %d\n",a,b,c); } } int main(){ //freopen("sort.in","r",stdin); //freopen("sort.out","w",stdout); int t=read();while(t--)slv(); fclose(stdin); fclose(stdout); return 0; } //Is that true?


测评信息: