fork download
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4. int n,m,q,st[1200006],lz[1200006];
  5. void UPDATE(int id, int l, int r, int u, int v, int vl)
  6. {
  7. if (l>v || r<u) return;
  8. else if (l>=u && r<=v)
  9. {
  10. st[id]+=vl,lz[id]+=vl;
  11. return;
  12. }
  13. int mid=(l+r)/2;
  14. lz[id*2]+=lz[id],st[id*2]+=lz[id],lz[id*2+1]+=lz[id],st[id*2+1]+=lz[id];
  15. UPDATE(id*2,l,mid,u,v,vl),UPDATE(id*2+1,mid+1,r,u,v,vl);
  16. st[id]=min(st[id*2],st[id*2+1]),lz[id]=0;
  17. }
  18. int GET(int id, int l, int r, int u, int v)
  19. {
  20. if (l>v || r<u) return 1e18;
  21. else if (l>=u && r<=v) return st[id];
  22. int mid=(l+r)/2,vl=lz[id];
  23. lz[id*2]+=vl,st[id*2]+=vl,lz[id*2+1]+=vl,st[id*2+1]+=vl,lz[id]=0;
  24. return min(GET(id*2,l,mid,u,v),GET(id*2+1,mid+1,r,u,v));
  25. }
  26. void UPDATE(int u, int v, int vl)
  27. {
  28. UPDATE(1,1,n,u,v,vl);
  29. }
  30. int GET(int u, int v)
  31. {
  32. return GET(1,1,n,u,v);
  33. }
  34. signed main()
  35. {
  36. ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
  37. freopen("duongsat.inp","r",stdin);
  38. freopen("duongsat.out","w",stdout);
  39. cin>>n>>m>>q;
  40. for (int i=1;i<=n;i++) UPDATE(i,i,m);
  41. for (int i=1;i<=q;i++)
  42. {
  43. int u,v,w;
  44. cin>>u>>v>>w;
  45. if (GET(u,v)>=w) cout<<"YES"<<'\n',UPDATE(u,v,-w);
  46. else cout<<"NO"<<'\n';
  47. }
  48. return 0;
  49. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty