Astral_Rider

Untitled

May 23rd, 2023
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int maxn = 1e5 + 5;
  5. int a[maxn], c[maxn], n;
  6.  
  7. inline int lowbit(int x) { return x & -x; }
  8. void build()
  9. {
  10.     for (int i = 1; i <= n; ++i)
  11.     {
  12.         c[i] += a[i];
  13.         int j = i + lowbit(i);
  14.         if (j <= n)
  15.             c[j] += c[i];
  16.     }
  17. }
  18. void add(int x, int k)
  19. {
  20.     while (x <= n)
  21.         c[x] = c[x] + k, x = x + lowbit(x);
  22. }
  23. int getsum(int x)
  24. {
  25.     int ans = 0;
  26.     while (x > 0)
  27.         ans = ans + c[x], x = x - lowbit(x);
  28.     return ans;
  29. }
  30.  
  31. int main()
  32. {
  33.     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  34.  
  35.     cin >> n;
  36.     for (int i = 1; i <= n; i++)
  37.         cin >> a[i];
  38.  
  39.     build();
  40.  
  41.     for (int i = 1; i <= 2 * n; i++)
  42.     {
  43.         int od, x, y;
  44.         cin >> od >> x >> y;
  45.         if (od == 1)
  46.             add(x, y - a[x]), a[x] = y;
  47.         else
  48.             cout << (getsum(y) - getsum(x - 1)) << '\n';
  49.     }
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment