D 题代码求条
  • 板块学术版
  • 楼主ikunTLE
  • 当前回复2
  • 已保存回复3
  • 发布时间2025/1/11 21:41
  • 上次更新2025/1/12 11:09:05
查看原帖
D 题代码求条
890515
ikunTLE楼主2025/1/11 21:41

过不了样例 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;
}
2025/1/11 21:41
加载中...