QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#575693 | #7939. High Towers | NKheyuxiang | ML | 2ms | 12096kb | C++14 | 1.3kb | 2024-09-19 16:18:14 | 2024-09-19 16:18:15 |
Judging History
answer
#include<bits/stdc++.h>
#define N 500005
using namespace std;
int n,a[N],b[N];
int hd,st[N],rp[N],go[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]<=(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) cout<<"oh no\n";
if(nnr==r) break;
if(nnr==nr||a[nnr]<=(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: 12096kb
input:
6 3 3 4 2 5 1
output:
2 1 2 1 3 1
result:
ok
Test #2:
score: 0
Accepted
time: 2ms
memory: 12064kb
input:
4 3 3 3 3
output:
4 3 2 1
result:
ok
Test #3:
score: -100
Memory Limit Exceeded
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:
oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no oh no ...