# bzoj2527[Poi2011] Meteors

540人阅读 评论(0)

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define inf 0x7fffffff
#define maxn 310000
typedef long long LL;

struct question
{
int l,r;LL c;
}q[maxn];
int m,len,nxt[maxn],first[maxn];
LL c[maxn],sd[maxn],cur[maxn],tmp[maxn];
int ans[maxn],tol[maxn],tor[maxn],id[maxn],to[maxn];
void ins(int x,int y)
{
to[++len]=y;
nxt[len]=first[x];
first[x]=len;
}
int lowbit(int x){return x&(-x);}
void change(int x,LL k)
{
for (x;x<=m;x+=lowbit(x)) c[x]+=k;
}
LL query(int x)
{
LL ret=0;
for (x;x>0;x-=lowbit(x)) ret+=c[x];
return ret;
}
void modify(int x,int y,LL z)
{
change(x,z);
change(y+1,-z);
}
void solve(int head,int tail,int l,int r)
{
int i,lnum=0,rnum=0;
int mid=(l+r)>>1;
if (l==r)
{
return;
}
for (i=l;i<=mid;i++)
{
if (q[i].l<=q[i].r) modify(q[i].l,q[i].r,q[i].c);
else modify(q[i].l,m,q[i].c),modify(1,q[i].r,q[i].c);
}
{
tmp[id[i]]=0;
for (int k=first[id[i]];k!=-1;k=nxt[k])
{
LL now=query(to[k]);
tmp[id[i]]+=now;
if (tmp[id[i]]+cur[id[i]]>sd[id[i]]) break;
}
if (tmp[id[i]]+cur[id[i]]>=sd[id[i]]) tol[++lnum]=id[i];
else {tor[++rnum]=id[i];cur[id[i]]+=tmp[id[i]];}
}
for (i=l;i<=mid;i++)
{
if (q[i].l<=q[i].r) modify(q[i].l,q[i].r,-q[i].c);
else modify(q[i].l,m,-q[i].c),modify(1,q[i].r,-q[i].c);
}
}
int main()
{
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
int n,i,x,k;
scanf("%d%d",&n,&m);len=0;
memset(c,0,sizeof(c));
memset(first,-1,sizeof(first));
for (i=1;i<=m;i++)
{
scanf("%d",&x);
ins(x,i);
}
for (i=1;i<=n;i++) {scanf("%d",&sd[i]);id[i]=i;}
scanf("%d",&k);
for (i=1;i<=k;i++)
scanf("%d%d%lld",&q[i].l,&q[i].r,&q[i].c);
k++;q[k].l=1;q[k].r=m;q[k].c=inf;
solve(1,n,1,k);
for (i=1;i<=n;i++)
if (ans[i]!=k) printf("%d\n",ans[i]);
else printf("NIE\n");
return 0;
}

个人资料
等级：
访问量： 7万+
积分： 2714
排名： 1万+
大佬们(友链)
最新评论