Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. const int MAXN = pow(2, 17);
  2.  
  3. struct segment_tree {
  4.     int tree[MAXN * 2];
  5.    
  6.     segment_tree() {}
  7.    
  8.     void change(int i, int d) {
  9.         i += MAXN;
  10.         while (i > 0) {
  11.             tree[i] += d;
  12.             i /= 2;
  13.         }
  14.     }
  15.    
  16.     int get(int i, int L, int R, int Ln, int Rn) {
  17.         if (R <= Ln || Rn <= L) return 0;
  18.         if (Ln <= L && R <= Rn) return tree[i];
  19.         int M = (L + R) / 2;
  20.         return get(i * 2, L, M, Ln, Rn) + get(i * 2 + 1, M, R, Ln, Rn);
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement