Alex_tz307

ARBORE INDEXAT BINAR

Aug 16th, 2021 (edited)
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1. const int MAXN = 1e5;
  2. int n, aib[1 + MAXN];
  3.  
  4. void update(int x, int t) {
  5.   for (int i = x; i <= n; i += i & -i)
  6.     aib[i] += t;
  7. }
  8.  
  9. int query(int x) {
  10.   int ans = 0;
  11.   for (int i = x; i > 0; i -= i & -i)
  12.     ans += aib[i];
  13.   return ans;
  14. }
  15.  
  16. int query_interval(int l, int r) {
  17.   return query(r) - query(l - 1);
  18. }
Add Comment
Please, Sign In to add comment