QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#422305#962. Thanks to MikeMirzayanovJohnAlfnovWA 0ms4080kbC++201.7kb2024-05-27 11:18:492024-05-27 11:18:50

Judging History

This is the latest submission verdict.

  • [2024-05-27 11:18:50]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 4080kb
  • [2024-05-27 11:18:49]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
int n,p[20005],s[20005];
vector<pair<int,int>>g[105];
void solve(int l,int r,int z){
	if(l==r)return;
	g[z].emplace_back(l,r);
	int mid=(l+r)>>1;
	solve(l,mid,z+1);solve(mid+1,r,z+1);
}
vector<int>vv[1005];
int ls[1005];
void charu(int x,int l,int r){
	for(int i=ls[x]+1;i<l;++i)vv[x].emplace_back(1);
	vv[x].emplace_back(r-l+1);
	ls[x]=r;
}
void rev(int x){
	while(ls[x]<n){
		vv[x].emplace_back(1);
		++ls[x];
	}
	int he=0;
	for(auto cu:vv[x]){
		reverse(p+he+1,p+he+cu+1);
		he+=cu;
	}
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&p[i]);
	solve(1,n,1);
	int he=0;
	for(int i=1;i<=100;++i)if(g[i].size()){
		int mx=0;
		for(auto pi:g[i]){
			int L=pi.first,R=pi.second,mid=(L+R)>>1;
			for(int j=L;j<=R;++j)s[j]=(p[j]>mid);
			int gs=0;
			while(1){
				int fl=1;
				for(int j=L;j<R;++j)fl&=(s[j]<=s[j+1]);
				if(fl)break;
				++gs;
				int ls=0,lx=0;
				vector<int>dc;
				for(int j=L;j<=R;++j){
					if(s[j]!=ls){
						dc.emplace_back(lx);
						ls=s[j];lx=1;
					}else ++lx;
				}
				dc.emplace_back(lx);
				int sz=dc.size(),zc=L;
				for(int j=0;j<sz;++j){
					int dd=dc[j];
					if(j%4==1&&j+1<sz){
						charu(he+gs,zc,zc+dd+dc[j+1]-1);
						reverse(s+zc,s+zc+dd+dc[j+1]);
						zc+=dd+dc[++j];
						continue;
					}
					if(dd)charu(he+gs,zc,zc+dd-1);
					zc+=dd;
				}
			}
			mx=max(mx,gs);
		}
		while(mx--)rev(++he);
	}
	if(he%2){
		vector<int>cv(n,1);
		vv[++he]=cv;
	}
	printf("%d\n",he);
	for(int i=1;i<=he;++i){
		auto cu=vv[i];
		if(i%2==0)reverse(cu.begin(),cu.end());
		printf("%d",(signed)cu.size());
		for(auto uc:cu)printf(" %d",uc);
		printf("\n");
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3748kb

input:

4
3 1 2 4

output:

2
2 3 1
3 1 1 2

result:

ok OK

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 4080kb

input:

6
6 5 4 3 2 1

output:

2
1 6
6 1 1 1 1 1 1

result:

wrong answer Integer 1 violates the range [2, 6]