QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#472754 | #7939. High Towers | ucup-team052 | WA | 6ms | 18428kb | C++23 | 4.3kb | 2024-07-11 19:03:52 | 2024-07-11 19:03:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
if(nega==-1) return -ans;
return ans;
}
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
#define N 500005
int a[N],n,ans[N];
struct SMT
{
#define ls (u<<1)
#define rs (u<<1|1)
#define mid ((l+r)/2)
int mx[N*4],tag[N*4];
void build(int u,int l,int r)
{
tag[u]=0;
if(l==r)
{
mx[u]=a[l];
return ;
}
build(ls,l,mid),build(rs,mid+1,r);
mx[u]=max(mx[ls],mx[rs]);
}
void upd(int u,int v) {mx[u]+=v,tag[u]+=v;}
void pushdown(int u)
{
upd(ls,tag[u]),upd(rs,tag[u]);
tag[u]=0;
}
void update(int u,int l,int r,int L,int R,int v)
{
if(L>R) return ;
if(L<=l&&r<=R) return upd(u,v);
pushdown(u);
if(mid>=L) update(ls,l,mid,L,R,v);
if(mid<R) update(rs,mid+1,r,L,R,v);
mx[u]=max(mx[ls],mx[rs]);
}
int qval(int u,int l,int r,int pos)
{
if(pos<1||pos>n) exit(0);
if(l==r) return mx[u];
pushdown(u);
if(pos<=mid) return qval(ls,l,mid,pos);
else return qval(rs,mid+1,r,pos);
}
int qval(int x) {return qval(1,1,n,x);}
int qmax(int u,int l,int r,int L,int R,int val)
{
if(L<=l&&r<=R)
{
if(mx[u]<=val) return -1;
if(l==r) return l;
int res=qmax(ls,l,mid,L,R,val);
if(res==-1) return qmax(rs,mid+1,r,L,R,val);
else return res;
}
pushdown(u);
if(mid>=L)
{
int res=qmax(ls,l,mid,L,R,val);
if(res!=-1) return res;
}
if(mid<R) return qmax(rs,mid+1,r,L,R,val);
return -1;
}
#undef mid
}smt;
int solve(int l,int r,int ad)
{
// printf("solveing %d %d :\n",l,r);
// for(int i=l;i<=r;i++) printf("%d%c",a[i]," \n"[i==r]);
if(r>n) exit(1);
if(l>r) return 0;
if(l==r)
{
ans[l]=ad+1;
return ans[l];
}
int mid=smt.qmax(1,1,n,l+1,r,a[l]);
// printf("%d %d %d\n",l,r,mid);
if(mid==-1)
{
ans[l]=ad+(r-l+1);
// for(int i=l+1;i<=r;i++) a[i]--;
smt.update(1,1,n,l+1,r,-1);
solve(l+1,r,ad);
return ans[l];
}
else
{
int premxcnt=smt.qval(l)-(mid-l);
int ansmx=0;
int w=mid-l;
// ans[l]=ans[mid]=ad+w;
// for(int i=l+1;i<=mid-1;i++) a[i]-=premxcnt+2;
smt.update(1,1,n,l+1,mid-1,-(premxcnt+2));
ansmx=max(ansmx,solve(l+1,mid-1,ad));
ad+=w;
// a[mid]-=w;
smt.update(1,1,n,mid,mid,-w);
int cur=mid;
// solving [cur + 1, r]
vector<int> tmppos; tmppos.push_back(cur); tmppos.push_back(l);
for(int i=0;i<premxcnt;)
{
int nw=cur+(smt.qval(cur)-premxcnt+i);
// printf("%d %d - %d ",l,r,nw);
if(smt.qval(nw)>nw-cur+premxcnt-i)
{ // h[nw]=h[cur]
// printf("=\n");
// for(int j=cur+1;j<=nw-1;j++) a[j]-=premxcnt-i+1;
smt.update(1,1,n,cur+1,nw-1,-(premxcnt-i+1));
ansmx=max(ansmx,solve(cur+1,nw-1,ad));
tmppos.push_back(nw);
// a[nw]-=(nw-cur);
smt.update(1,1,n,nw,nw,-(nw-cur));
cur=nw;
}
else
{ // h[nw+1] is premx
// printf(">\n");
// for(int j=cur+1;j<=nw;j++) a[j]-=premxcnt-i+1;
smt.update(1,1,n,cur+1,nw,-(premxcnt-i+2));
ansmx=max(ansmx,solve(cur+1,nw,ad));
ansmx++;
for(int i:tmppos) ans[i]=ansmx;
tmppos.clear();
tmppos.push_back(nw+1);
ad=ansmx;
// a[nw+1]-=(nw+1-l);
smt.update(1,1,n,nw+1,nw+1,-(nw+1-l));
cur=nw+1;
i++;
}
}
while(cur<r)
{
int nw=cur+smt.qval(cur);
if(nw<r)
{
// for(int i=cur+1;i<nw;i++) a[i]-=2;
smt.update(1,1,n,cur+1,nw-1,-2);
ansmx=max(ansmx,solve(cur+1,nw-1,ad));
// a[nw]-=(nw-cur);
smt.update(1,1,n,nw,nw,-(nw-cur));
cur=nw;
tmppos.push_back(cur);
}
else
{
// for(int i=cur+1;i<=r;i++) a[i]--;
smt.update(1,1,n,cur+1,r,-1);
ansmx=max(ansmx,solve(cur+1,r,ad));
cur=r+1;
}
}
// assert(tmppos.size()>=1);
ansmx++;
for(int i:tmppos) ans[i]=ansmx;
return ansmx;
}
}
signed main()
{
n=read();
for(int i=1;i<=n;i++) a[i]=read();
smt.build(1,1,n);
solve(1,n,0);
for(int i=1;i<=n;i++) printf("%d%c",ans[i]," \n"[i==n]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9936kb
input:
6 3 3 4 2 5 1
output:
4 1 4 3 6 5
result:
ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 9860kb
input:
4 3 3 3 3
output:
4 3 2 1
result:
ok
Test #3:
score: -100
Wrong Answer
time: 6ms
memory: 18428kb
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:
result:
wrong output format Unexpected end of file - int32 expected