Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. struct FenwTree{
  2.     vi t;
  3.     int n;
  4.     FenwTree(int _n){
  5.         n = _n;
  6.         t.assign(n, 0);
  7.     }
  8.     void add(int i, int x){
  9.         for(;i<n;i=(i|(i+1)))
  10.             t[i] += x;
  11.     }
  12.     int get(int i){
  13.         int res = 0;
  14.         for(;i>=0;i=(i&(i+1))-1)
  15.             res += t[i];
  16.         return res;
  17.     }
  18. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement