QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#575711#7939. High TowersNKheyuxiangWA 27ms10976kbC++141.3kb2024-09-19 16:23:012024-09-19 16:23:02

Judging History

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

  • [2024-09-19 16:23:02]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:10976kb
  • [2024-09-19 16:23:01]
  • 提交

answer

#include<bits/stdc++.h>
#define N 500005
using namespace std;
int n,a[N],b[N];
int hd,st[N],rp[N];
int solve(int l,int r,int dl){
	if(l>r) return 0;
	int p=rp[l];
	if(p>r){
		b[l]=solve(l+1,r,dl+1)+1;
		return b[l];
	}
	int s=a[l]-dl-(p-l+1);
	int nl=l,nr=p,ty=0,res=0;
	if(nl+1<nr) res=max(res,solve(nl+1,nr-1,dl+2+s));
	while(1){
		int nnr=nr+(a[nr]-dl-s-((ty==0)?(nr-nl+1):(nr-l+1)));
		if(nnr>r) cout<<"oh no\n";
		if(nnr>=r){
			res=max(res,solve(nr+1,r,dl+1));
			break;
		}
		if(nnr==nr||a[nnr]-dl<=(nnr-nr+1)+s){
			res=max(res,solve(nr+1,nnr,dl+1+s));
			nl=nr,nr=nnr+1;s--;ty=1;
		}
		else{
			res=max(res,solve(nr+1,nnr-1,dl+2+s));
			nl=nr,nr=nnr;ty=0;
		}
	}
	b[l]=++res;
	s=a[l]-dl-(p-l+1);
	nl=l,nr=p,ty=0;
//	cout<<"solve "<<l<<" "<<r<<" "<<dl<<endl;
	while(1){
		b[nr]=b[nl]+ty;
		int nnr=nr+(a[nr]-dl-s-((ty==0)?(nr-nl+1):(nr-l+1)));
//		cout<<nr<<"-"<<nnr<<"  ";
		if(nnr>=r) break;
		if(nnr==nr||a[nnr]-dl<=(nnr-nr+1)+s){nl=nr,nr=nnr+1;s--;ty=1;}
		else{nl=nr,nr=nnr;ty=0;}
	}
//	cout<<endl;
	return res;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),a[i]++;
	st[hd=0]=n+1;
	for(int i=n;i>=1;i--){
		while(hd>0&&a[st[hd]]<=a[i]) hd--;
		rp[i]=st[hd];
		st[++hd]=i;
	} 
	solve(1,n,0);
	for(int i=1;i<=n;i++) printf("%d ",b[i]);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6
3 3 4 2 5 1

output:

2 1 2 1 3 1 

result:

ok 

Test #2:

score: 0
Accepted
time: 1ms
memory: 10036kb

input:

4
3 3 3 3

output:

4 3 2 1 

result:

ok 

Test #3:

score: -100
Wrong Answer
time: 27ms
memory: 10976kb

input:

264668
5 5 5 5 9 5 5 5 7 3 5 3 11 9 9 9 8 9 8 9 12 4 4 9 5 5 6 4 12 4 7 5 6 5 18 12 6 12 11 11 11 11 11 11 12 19 5 5 8 6 6 6 26 7 7 7 8 6 7 6 6 12 10 6 9 8 8 8 10 4 22 4 4 6 3 6 4 4 8 5 5 5 7 3 8 6 6 6 6 8 3 5 3 6 4 4 8 5 5 5 10 6 6 6 6 17 4 12 5 11 6 10 7 9 8 8 16 5 5 5 8 4 4 12 8 7 7 8 6 9 4 14 5 ...

output:

13 3 2 1 13 3 2 1 13 1 13 1 13 5 4 3 2 2 1 3 13 2 1 13 2 1 2 1 13 3 3 2 2 1 13 8 7 7 6 5 4 3 2 1 8 13 4 1 4 3 2 1 13 5 2 1 5 5 5 2 1 6 6 4 4 3 2 1 6 1 13 2 1 13 1 13 2 1 13 3 2 1 13 1 13 4 3 2 1 13 1 13 1 13 2 1 13 3 2 1 13 4 3 2 1 13 6 6 5 5 4 4 3 3 2 1 13 3 2 1 13 2 1 13 3 2 1 2 1 3 1 13 2 1 2 1 1...

result:

wrong answer