Advertisement
Khody

Untitled

Mar 17th, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <algorithm>
  4. #include <iomanip>
  5. #include <random>
  6. #include <ctime>
  7. #include <bitset>
  8. #include <map>
  9. #include <set>
  10. #include <unordered_map>
  11. #include <unordered_set>
  12. #include <cmath>
  13. #include <climits>
  14. #include <cstring>
  15. #include <queue>
  16. #include <deque>
  17. #include <list>
  18. #include <stack>
  19.  
  20. #define pb push_back
  21. #define ff first
  22. #define ss second
  23. #define sqr(x) (x) * (x)
  24. #define cb(x) (x) * (x) * (x)
  25. #define all(x) (x).begin(), (x).end()
  26.  
  27.  
  28. using namespace std;
  29.  
  30. typedef long long ll;
  31. typedef long double ld;
  32. typedef pair<int, int> pii;
  33. typedef pair<ll, ll> pll;
  34.  
  35. const int inf = 2e9;
  36. const ll linf = 2e18;
  37. //const ll mod = 1e9 + 7;
  38. const ll mod = 998244353;
  39.  
  40. template <typename T>
  41. ostream& operator << (ostream& s, vector<T>& v) {
  42.     for (auto el : v) {
  43.         s << el << " ";
  44.     }
  45.     return s;
  46. }
  47.  
  48.  
  49. ll t[400000];
  50.  
  51. void modify(int v, int vl, int vr, int pos, int value) {
  52.     if (pos < vl || pos > vr) return;
  53.     if (vl == vr) {
  54.         t[v] = value;
  55.         return;
  56.     }
  57.     int vm = vl + (vr - vl) / 2;
  58.     if (pos <= vm) modify(2 * v + 1, vl, vm, pos, value);
  59.     else modify(2 * v + 2, vm + 1, vr, pos, value);
  60.     t[v] = t[2 * v + 1] + t[2 * v + 2];
  61. }
  62.  
  63.  
  64. ll query(int v, int vl, int vr, int l, int r) {
  65.     if (vl > r || vr < l) return 0;
  66.     if (vl >= l && vr <= r) return t[v];
  67.     int vm = vl + (vr - vl) / 2;
  68.     ll lq = query(2 * v + 1, vl, vm, l, r);
  69.     ll rq = query(2 * v + 2, vm + 1, vr, l, r);
  70.     return lq + rq;
  71. }
  72.  
  73.  
  74. void solve() {
  75.     for (int i = 0; i < 400000; i++) t[i] = 0;
  76.     int n, q; cin >> n >> q;
  77.     for (int i = 0; i < q; i++) {
  78.         int t, x, y; cin >> t >> x >> y;
  79.         if (t == 1) modify(0, 0, n - 1, x - 1, y);
  80.         else cout << query(0, 0, n - 1, x - 1, y - 1) << endl;
  81.     }
  82. }
  83.  
  84. int main() {
  85.     ios_base::sync_with_stdio(0);
  86.     cin.tie(0), cout.tie(0);
  87.     int q; cin >> q;
  88.     while (q--) solve();
  89.     return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement