过不了样例 3,如果思路有问题烦请指出。
#include<bits/stdc++.h>
using namespace std;
#define int long long
int read(){int x=0;char f=1,ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();return x*f;}
const int N=5e5+10;
int a[N];
bool vis[N];
struct node{
int x,id;
friend bool operator<(const node cmp_x,const node cmp_y){
return cmp_x.x>cmp_y.x;
}
};priority_queue<node>pq;
signed main(){
int n=read();
for(int i=1;i<=n;++i)
a[i]=read();
int cnt=0,ans=0;
for(int i=1;i<=n;++i){
pq.push({a[i]+i,i});
a[i]+=pq.size();
while(!pq.empty()&&pq.top().x-i+1<=0){
vis[pq.top().id]=true;
pq.pop();
}
}
for(int i=1;i<=n;++i)
if(vis[i])
printf("0 ");
else printf("%lld ",a[i]-(n-i+1));
printf("\n");
return 0;
}