提交时间:2024-10-18 14:00:05

运行 ID: 33670

#include<bits/stdc++.h> #define int long long using namespace std; const int maxn=5e5+7; int n,m,k,d; struct Node{ int Lm,Rm,Sum,Mx; Node(int v=0){Lm=Rm=Sum=Mx=v;} }; Node operator+(const Node A,const Node B){ Node ret(0); ret.Lm=max(A.Lm,A.Sum+B.Lm); ret.Rm=max(B.Rm,B.Sum+A.Rm); ret.Sum=A.Sum+B.Sum; ret.Mx=max(max(A.Mx,B.Mx),A.Rm+B.Lm); return ret; } #define lc(p) ((p)<<1) #define rc(p) ((p)<<1|1) int a[maxn]; struct SGT{ Node d[maxn]; inline void pu(int p){d[p]=d[lc(p)]+d[rc(p)];} inline void B(int p,int l,int r){ if(l==r)return void(d[p]=Node(a[l])); int mid=l+r>>1; B(lc(p),l,mid);B(rc(p),mid+1,r); pu(p); } inline void U(int p,int l,int r,int x,int dt){ if(l==r){a[x]+=dt;return void(d[p]=Node(a[x]));} int mid=l+r>>1; if(x<=mid)U(lc(p),l,mid,x,dt); else U(rc(p),mid+1,r,x,dt); pu(p); } inline int Q_All(){return d[1].Mx;} }T; signed main(){ cin>>n>>m>>k>>d; cout<<n<<" "<<m<<" "<<k<<" "<<d<<endl; for(int i=1;i<=n;i++)a[i]-=k; T.B(1,1,n); while(m--){ int x,y; cin>>x>>y; T.U(1,1,n,x,y); if(T.Q_All()>k*d)cout<<"NO"<<endl; else cout<<"YES"<<endl; } }