QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#287582#7960. 排序大师CrysflyWA 3ms7748kbC++171.6kb2023-12-20 19:32:352023-12-20 19:32:36

Judging History

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

  • [2023-12-20 19:32:36]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:7748kb
  • [2023-12-20 19:32:35]
  • 提交

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;
					}
				}
				if(!ok) continue;
				assert(ok);
				break;
			}
	}
	cout<<arr.size()<<"\n";
	for(auto [a,b,c,d]:arr)cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
	return 0;
}
/*

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
1

output:

0

result:

ok orz U R the sorting master!

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 7748kb

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:

984
1 3 394 418
2 3 999 1008
3 5 199 1039
4 10 1758 1924
5 7 926 979
6 102 1926 1936
7 202 1957 1969
8 10 907 1788
9 10 1447 1512
10 13 1598 1781
11 15 1123 1212
12 17 1421 1473
13 31 1666 1753
14 15 39 1642
16 17 1558 1952
17 46 1917 1931
18 36 1855 1927
19 20 192 476
20 21 634 1386
21 72 1911 1948...

result:

wrong answer Step is not the minimal