Submission #1283654

#TimeUsernameProblemLanguageResultExecution timeMemory
1283654VMaksimoski008XORanges (eJOI19_xoranges)C++20
100 / 100
59 ms4564 KiB
#include <bits/stdc++.h>
using namespace std;

struct fenwick {
    int n;
    vector<int> tree;

    void init(int _n) {
        n = _n + 10;
        tree.resize(n+10);
    }

    void update(int p, int v) {
        for(p++; p<n; p+=p&-p) tree[p] ^= v;
    }

    int query(int p) {
        int ans = 0;
        for(p++; p; p-=p&-p) ans ^= tree[p];
        return ans;
    }

    int query(int l, int r) {
        return query(r) ^ query(l-1);
    }
};

signed main() {
    ios_base::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);

    int n, q; cin >> n >> q;
    vector<int> a(n+1);
    for(int i=1; i<=n; i++) cin >> a[i];

    fenwick fwt[2];
    fwt[0].init(n);
    fwt[1].init(n);

    for(int i=1; i<=n; i++)
        fwt[i&1].update(i, a[i]);

    while(q--) {
        int t, l, r; cin >> t >> l >> r;

        if(t == 1) {
            fwt[l&1].update(l, a[l]^r);
            a[l] = r;
        } else {
            cout << ((r-l) % 2 ? 0 : fwt[l&1].query(l, r)) << '\n';
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...