Fshl0

Fenwick Tree

Apr 1st, 2021
692
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void upd (int i, int val) {
  2.     for (; i <= n; i += (i & -i))
  3.         pre[i] += val;
  4.     return;
  5. }
  6.  
  7. int get (int i) {
  8.     int res = 0;
  9.     for (; i > 0; i -= i & (-i))
  10.         res += pre[i];
  11.     return res;
  12. }
RAW Paste Data