QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#87772#962. Thanks to MikeMirzayanoveyiigjknWA 2ms3752kbC++142.0kb2023-03-14 09:37:072023-03-14 09:37:09

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-14 09:37:09]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3752kb
  • [2023-03-14 09:37:07]
  • 提交

answer

# include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using vi=vector<int>;
int a[20010];
bool rev=0;
vector<pii> seg;
vector<vi> ans;
void work(const vector<pii> &vec)
{
	ans.emplace_back();
	for(auto &i:(rev?vector<pii>(vec.rbegin(),vec.rend()):vec))
		ans.back().emplace_back(i.second-i.first+1);
	for(auto &i:vec) reverse(a+i.first,a+i.second+1);
}
pair<vector<pii>,bool> calc(int l,int r,int mid)
{
	if(l==r) return {{{l,r}},1};
	int tot=0;
	bool done=0;
	static pii b[20010];
	vector<pii> vec;
	for(int i=l,j;i<=r;i=j+1)
	{
		for(j=i;j<r && (a[i]<=mid)==(a[j+1]<=mid);j++);
		b[++tot]={i,j};
	}
	if(tot==2)
		if(a[l]<=mid) vec={b[1],b[2]},done=1;
		else vec={{l,r}};
	else if(tot==3 && a[l]>mid) vec={{b[1].first,b[2].second},b[3]};
	else
	{
		int p=(a[l]<=mid)+1;
		vec.push_back(b[1]);
		for(;p<tot;p+=2)
			if(p/2&1) vec.emplace_back(b[p].first,b[p+1].second);
			else vec.push_back(b[p]),vec.push_back(b[p+1]);
		if(p<=tot) vec.push_back(b[tot]);
	}
	return {vec,done};
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	seg.emplace_back(1,n);
	while(1)
	{
		bool done=1;
		vector<pii> tseg;
		for(auto &i:seg) done&=(i.first==i.second);
		if(done) break;
		while(1)
		{
			done=1;
			vector<pii> vec;
			for(auto &i:seg)
			{
				auto p=calc(i.first,i.second,(i.first+i.second)/2);
				done&=p.second;
				vec.insert(vec.end(),p.first.begin(),p.first.end());
			}
			if(done) break;
			if(vec.size()>1) work(vec);
			else reverse(a+1,a+n+1);
			rev^=1;
		}
		for(auto &i:seg)
		{
			int l=i.first,r=i.second,mid=(l+r)/2;
			if(l==r) tseg.push_back(i);
			else tseg.emplace_back(l,mid),tseg.emplace_back(mid+1,r);
		}
		seg.swap(tseg);
	}
	if(rev)
	{
		ans.emplace_back(n);
		fill(ans.back().begin(),ans.back().end(),1);
	}
	cout<<ans.size()<<endl;
	for(auto &i:ans)
	{
		printf("%d",(int)i.size());
		for(int j:i) printf(" %d",j);
		puts("");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3588kb

input:

4
3 1 2 4

output:

2
2 3 1
3 1 1 2

result:

ok OK

Test #2:

score: 0
Accepted
time: 2ms
memory: 3616kb

input:

6
6 5 4 3 2 1

output:

1
6 1 1 1 1 1 1

result:

ok OK

Test #3:

score: 0
Accepted
time: 0ms
memory: 3512kb

input:

1
1

output:

0

result:

ok OK

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 3752kb

input:

10
3 8 7 4 6 2 9 10 1 5

output:

6
5 1 3 1 1 4
3 2 6 2
6 1 1 2 2 3 2
4 2 3 1 4
8 1 2 1 1 1 2 1 1
9 1 1 1 1 1 1 1 1 2

result:

wrong answer total size of all parts is not equal to size of premutation