Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 500017;
  6. int t[N * 4];
  7. int mas[N];
  8. void build (int v, int tl, int tr) {
  9.     if (tl == tr)
  10.         t[v] = mas[tl];
  11.     else {
  12.         int tm = (tl + tr) / 2;
  13.         build (v*2, tl, tm);
  14.         build (v*2+1, tm+1, tr);
  15.         t[v] = t[v*2] ^ t[v*2+1];
  16.     }
  17. }
  18.  
  19. int get_xor (int v, int tl, int tr, int l, int r) {
  20.     if (l > r)
  21.         return 0;
  22.     if (l == tl && r == tr)
  23.         return t[v];
  24.     int tm = (tl + tr) / 2;
  25.     return get_xor (v*2, tl, tm, l, min(r,tm))
  26.         ^ get_xor (v*2+1, tm+1, tr, max(l,tm+1), r);
  27. }
  28.  
  29. void update (int v, int tl, int tr, int pos, int new_val) {
  30.     if (tl == tr)
  31.         t[v] = new_val;
  32.     else {
  33.         int tm = (tl + tr) / 2;
  34.         if (pos <= tm)
  35.             update (v*2, tl, tm, pos, new_val);
  36.         else
  37.             update (v*2+1, tm+1, tr, pos, new_val);
  38.         t[v] = t[v*2] ^ t[v*2+1];
  39.     }
  40. }
  41. int main() {
  42.     ios::sync_with_stdio(false);
  43.     cin.tie(0); cout.tie(0);
  44.     int n, m;
  45.     cin >> n >> m;
  46.     vector <pair <int, pair <int, int> >  > q(m);
  47.     for (int i = 0; i < n; ++i) {
  48.         cin >> mas[i];
  49.     }
  50.     for (int i = 0; i < m; ++i) {
  51.         cin >> q[i].first >> q[i].second.first >> q[i].second.second;
  52.     }
  53.     build(1, 0, N - 1);
  54.     for (int i = 0; i < m; i++) {
  55.         int type = q[i].first;
  56.         if (type == 1) {
  57.             int l = q[i].second.first, r = q[i].second.second;
  58.             cout << get_xor(1, 0, N - 1, l, r) << endl;
  59.         } else {
  60.             int x = q[i].second.first, val = q[i].second.second;
  61.             update(1, 0, N - 1, x, val);
  62.         }
  63.     }
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement