Advertisement
pdpd123

Untitled

Jul 6th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. struct node{
  2.     node *l, *r;
  3.     int v = 0;
  4.     node(): l(nullptr), r(nullptr) {}
  5.     node(node *l, node *r): l(l), r(r) {pull();}
  6.     void pull() {if(l) v = max(l->v, r->v);}
  7. };
  8.  
  9. node *build(int l,int r) {
  10.     int mid = l+r >> 1;
  11.     if(l+1 == r) return new node;
  12.     return new node(build(l, mid), build(mid, r));
  13. }
  14.  
  15. void add(node *a, int l, int r, int pos, int v) {
  16.     int mid = l+r >> 1;
  17.     if(l+1 == r) a->v += v;
  18.     else if(m <= pos) add(a->r, m, r, pos, v);
  19.     else add(a->l, l, m, pos, v);
  20.     a->pull();
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement