Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. int query(int idx){
  2. int sum=0;
  3. while(idx>0){
  4. sum+=tree[idx];
  5. idx -= idx & (-idx);
  6. }
  7. return sum;
  8. }
  9.  
  10. void update(int idx, int x, int n) //n is the size of the array, x is the number to add
  11. {
  12. while(idx<=n)
  13. {
  14. tree[idx]+=x;
  15. idx += idx & (-idx);
  16. }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement