QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#287580#7960. 排序大师CrysflyRE 1ms5648kbC++171.6kb2023-12-20 19:31:312023-12-20 19:31:31

Judging History

你现在查看的是最新测评结果

  • [2023-12-20 19:31:31]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5648kb
  • [2023-12-20 19:31:31]
  • 提交

answer

// what is matter? never mind. 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2") 
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int long long
#define ull unsigned long long
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
 
#define maxn 500005
#define inf 0x3f3f3f3f

int n;
int pos[maxn],a[maxn];
vector<array<int,4>>arr;

int t[maxn],m;
void op(int a,int b,int c,int d){
	m=0;
	For(i,1,a-1)t[++m]=::a[i];
	For(i,c,d)t[++m]=::a[i];
	For(i,b+1,c-1)t[++m]=::a[i];
	For(i,a,b)t[++m]=::a[i];
	For(i,d+1,n)t[++m]=::a[i];
	For(i,1,n)::a[i]=t[i],pos[::a[i]]=i;
	arr.pb({a,b,c,d});
}
bool chk(){
	For(i,1,n)if(a[i]!=i)return 0;
	return 1;
}

signed main()
{
	n=read();
	For(i,1,n)a[i]=read(); a[n+1]=n+1;
	while(!chk()){
		For(i,1,n+1) pos[a[i]]=i;
		For(i,1,n)
			if(a[i]!=i){
				bool ok=0;
				For(j,i+1,pos[i]-1){
					int x=pos[a[j]+1];
					if(x>pos[i]){
						ok=1;
						op(i,j,pos[i],x-1);
						break;
					}
				}
				assert(ok);
				break;
			}
	}
	cout<<arr.size()<<"\n";
	for(auto [a,b,c,d]:arr)cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
	return 0;
}
/*

*/

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5648kb

input:

1
1

output:

0

result:

ok orz U R the sorting master!

Test #2:

score: -100
Runtime Error

input:

1970
1452 1799 174 371 132 637 23 1510 1819 1794 1665 450 1183 564 1305 548 554 1310 701 1454 1843 1498 1040 1678 77 614 1928 1761 1718 1637 1853 1026 1804 1062 805 864 1859 586 663 346 335 681 152 1768 1639 1713 856 1401 1833 1350 1842 558 241 1829 802 581 1958 845 722 239 1793 1118 1251 1892 1949 ...

output:


result: