1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
#include<iostream> #include<cstdio> #include<vector> #include<cstring> #include<ctime> using namespace std; int read() { int x=0,f=1; char c=getchar(); while(!isdigit(c)){if(c=='-') f=-1;c=getchar();} while(isdigit(c)){x=x*10+c-'0';c=getchar();} return x*f; } const int N=300000+100; const int inf=0x3f3f3f3f; int n,m,K,ans[N],w[N]; struct BIT { long long t[N<<2]; inline int lowbit(int &x){return x&(-x);} void Init() { memset(t,0,sizeof t); } long long Query(int x) { long long sum=0; while(x>0) { sum+=t[x]; x-=lowbit(x); } return sum; } void update(int x,int dlt) { while(x<=m) { t[x]+=dlt; x+=lowbit(x); } } void Change(int l,int r,int w) { update(r+1,-w); update(l,w); } }bit; struct OP { int l,r,w; }op[N]; vector <int> a[N]; struct DL { int l,r; vector <int> c; }mqueue[N+5000]; int main() {
n=read(),m=read(); for(int i=1;i<=m;i++) a[read()].push_back(i); for(int i=1;i<=n;i++) w[i]=read(); K=read(); for(int i=1;i<=K;i++) op[i].l=read(),op[i].r=read(),op[i].w=read();
int front=0,tail=0,T=1; mqueue[tail].l=1,mqueue[tail].r=K+1; for(int i=1;i<=n;i++) mqueue[tail].c.push_back(i); tail++; while(tail!=front) { if(mqueue[front].l==mqueue[front].r) { for(int i=0;i<int(mqueue[front].c.size());i++) ans[mqueue[front].c[i]]=mqueue[front].l; front=(front+1)%(K+5000); continue; } int mid=(mqueue[front].l+mqueue[front].r)/2; if(T>mid) T=1,bit.Init(); for(;T<=mid;T++) if(op[T].l<=op[T].r) bit.Change(op[T].l,op[T].r,op[T].w); else bit.Change(op[T].l,m,op[T].w), bit.Change(1,op[T].r,op[T].w); vector <int> l,r; for(int i=0;i<int(mqueue[front].c.size());i++) { long long t_ans=0,now=mqueue[front].c[i]; for(int j=0;j<int(a[now].size());j++) { t_ans+=bit.Query(a[now][j]); if(t_ans>inf) break; } if(t_ans>=w[now]) l.push_back(now); else r.push_back(now); } mqueue[tail].l=mqueue[front].l,mqueue[tail].r=mid,mqueue[tail++].c=l; tail%=(K+5000); mqueue[tail].l=mid+1,mqueue[tail].r=mqueue[front].r,mqueue[tail++].c=r; tail%=(K+5000); front=(front+1)%(K+5000); }
for(int i=1;i<=n;i++) if(ans[i]==K+1) printf("NIE\n"); else printf("%d\n",ans[i]); return 0; }
|