QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#472652 | #7939. High Towers | ucup-team052# | TL | 1ms | 6076kb | C++23 | 2.6kb | 2024-07-11 17:59:15 | 2024-07-11 17:59:15 |
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];
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=-1;
for(int i=l+1;i<=r;i++) if(a[i]>a[l])
{
mid=i;
break;
}
// 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]--;
solve(l+1,r,ad);
return ans[l];
}
else
{
int premxcnt=a[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;
ansmx=max(ansmx,solve(l+1,mid-1,ad));
ad+=w;
a[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+(a[cur]-premxcnt+i);
// printf("%d %d - %d ",l,r,nw);
if(a[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;
ansmx=max(ansmx,solve(cur+1,nw-1,ad));
tmppos.push_back(nw);
a[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;
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);
cur=nw+1;
i++;
}
}
while(cur<r)
{
int nw=cur+a[cur];
if(nw<=r)
{
for(int i=cur+1;i<nw;i++) a[i]--;
ansmx=max(ansmx,solve(cur+1,nw-1,ad));
a[nw]-=(nw-cur);
cur=nw;
tmppos.push_back(cur);
}
else
{
for(int i=cur+1;i<=r;i++) a[i]--;
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();
solve(1,n,0);
for(int i=1;i<=n;i++) printf("%d%c",ans[i]," \n"[i==n]);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5844kb
input:
6 3 3 4 2 5 1
output:
4 1 4 3 5 5
result:
ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 6076kb
input:
4 3 3 3 3
output:
4 3 2 1
result:
ok
Test #3:
score: -100
Time 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 ...