比赛 EYOI与SBOI开学欢乐赛6th 评测结果 WAWWWWAWTW
题目名称 简短的题目 最终得分 20
用户昵称 遥时_彼方 运行时间 2.602 s
代码语言 C++ 内存使用 7.69 MiB
提交时间 2022-09-19 20:23:28
显示代码纯文本
#include<bits/stdc++.h>
#define rep(x,y,z) for(int x=y;x<=z;x++)
#define drep(x,y,z) for(int x=y;x>=z;x--)
#define ull unsigned long long
#define ll long long
using namespace std;
inline int read()
{
	int x=0;bool flag=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')flag=0;ch=getchar();}
	while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	if(flag) return x;
	return ~(x-1);
} 
inline void write(ll x)
{
	if(x<0) {x=~(x-1);putchar('-');}
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
/////////////////////////////
const int N=1e5+50;
int nc,lc,rc;
ll a[N];
int b[N];
ll c[N];
ll ans[N];
struct sor
{
	int sz;
	int l;
	int r;
};
struct cmp
{
	bool operator()(sor x,sor y)
	{
		return x.sz<y.sz;
	}
};
priority_queue <sor,vector<sor>,cmp> q;
int main()
{
    freopen("wwydatsv.in","r",stdin);
	freopen("wwydatsv.out","w",stdout);
    nc=read(),lc=read(),rc=read();
    rep(i,1,nc) a[i]=read();
    ll sum=0; 
    rep(i,1,nc)
    {
    	if(a[i]>=0) b[i]=i,c[i]=a[i];
    	else 
    	{
    		rep(o,i,i+rc-1)
    		{
    			sum+=a[o];
    			if(sum>=0) 
    			{
    				b[i]=o;
    				c[i]=sum;
    				break;
				}
			}
		}
		if(!b[i]) b[i]=99999999;
	}
//	cout<<"P1\n";
	sum=0;
    rep(i,1,lc) sum+=a[i];
    int l=1,r=lc;
    sor z;
    while(r!=nc)
    {
//		cout<<l<<" "<<r<<"Pb\n";
    	if(r-l+1==rc)
    	{
    		z=q.top();	
    		while(l<z.l||l>z.r) q.pop(),z=q.top();
    		ans[l]=z.sz;
    		sum-=a[l++];
    		z.sz=sum,z.l=l,z.r=r;
    		q.push(z);
		}
		else if(r-l+1<=lc||b[r+1]-l+1<=rc||a[l]>0)
		{
			if(b[r+1]-l+1<=rc) sum+=c[++r],r=b[r];
			else sum+=a[++r];
    		z.sz=sum,z.l=l,z.r=r;
    		q.push(z);
		}
		else 
		{
			z=q.top();	
    		while(l<z.l||l>z.r) q.pop(),z=q.top();
    		ans[l]=z.sz;
    		sum-=a[l++];
    		z.sz=sum,z.l=l,z.r=r;
    		q.push(z);
		}
//		cout<<l<<" "<<r<<"Pe\n";
	}
//	cout<<"P2\n";
	while(r-l+1>=lc)
	{
		z=q.top();	
    	while(l<z.l||l>z.r) q.pop(),z=q.top();
    	ans[l]=z.sz;
    	sum-=a[l++];
    	z.sz=sum,z.l=l,z.r=r;
    	q.push(z);
	}
//	cout<<"P3\n";
	while(l<=r)
	{	
		z=q.top();	
    	while(l<z.l||l>z.r) q.pop(),/*cout<<z.sz<<endl,*/z=q.top();
    	ans[l++]=z.sz;
	}
//	cout<<"P4\n";
	rep(i,1,nc) write(ans[i]),putchar(32);
    return 0;
}