Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 500017;
- int t[N * 4];
- int mas[N];
- void build (int v, int tl, int tr) {
- if (tl == tr)
- t[v] = mas[tl];
- else {
- int tm = (tl + tr) / 2;
- build (v*2, tl, tm);
- build (v*2+1, tm+1, tr);
- t[v] = t[v*2] ^ t[v*2+1];
- }
- }
- int get_xor (int v, int tl, int tr, int l, int r) {
- if (l > r)
- return 0;
- if (l == tl && r == tr)
- return t[v];
- int tm = (tl + tr) / 2;
- return get_xor (v*2, tl, tm, l, min(r,tm))
- ^ get_xor (v*2+1, tm+1, tr, max(l,tm+1), r);
- }
- void update (int v, int tl, int tr, int pos, int new_val) {
- if (tl == tr)
- t[v] = new_val;
- else {
- int tm = (tl + tr) / 2;
- if (pos <= tm)
- update (v*2, tl, tm, pos, new_val);
- else
- update (v*2+1, tm+1, tr, pos, new_val);
- t[v] = t[v*2] ^ t[v*2+1];
- }
- }
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(0); cout.tie(0);
- int n, m;
- cin >> n >> m;
- vector <pair <int, pair <int, int> > > q(m);
- for (int i = 0; i < n; ++i) {
- cin >> mas[i];
- }
- for (int i = 0; i < m; ++i) {
- cin >> q[i].first >> q[i].second.first >> q[i].second.second;
- }
- build(1, 0, N - 1);
- for (int i = 0; i < m; i++) {
- int type = q[i].first;
- if (type == 1) {
- int l = q[i].second.first, r = q[i].second.second;
- cout << get_xor(1, 0, N - 1, l, r) << endl;
- } else {
- int x = q[i].second.first, val = q[i].second.second;
- update(1, 0, N - 1, x, val);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement