Advertisement
Jasir

2D BIT

Jun 17th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1.  
  2. int read(int idy, int idx){
  3.     int sum = 0;
  4.     while(idy>0){
  5.         int tmp = idx;
  6.         while(idx>0){
  7.             sum += tree[idy][idx];
  8.             idx -= (idx&-idx);
  9.         }
  10.         idx = tmp;
  11.         idy -= (idy&-idy);
  12.     }
  13.     return sum;
  14. }
  15.  
  16. void update(int idy, int idx, int val){
  17.     while(idy<=mx){
  18.         int tmp = idx;
  19.         while(idx<=mx){
  20.             tree[idy][idx] += val;
  21.             idx += (idx&-idx);
  22.         }
  23.         idx = tmp;
  24.         idy += (idy&-idy);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement