Submission #1340620

#TimeUsernameProblemLanguageResultExecution timeMemory
1340620kawhietXORanges (eJOI19_xoranges)C++20
100 / 100
102 ms8684 KiB
#include <bits/stdc++.h>
using namespace std;

struct SegmentTree {
    int n;
    vector<int> t;

    SegmentTree(int _n) {
        n = _n;
        t.resize(4 * n);
    }

    int merge(int x, int y) {
        return x ^ y;
    }

    void update(int id, int tl, int tr, int i, int v) {
        if (tl == tr) {
            t[id] = v;
            return;
        }
        int x = (id << 1) + 1, y = x + 1, tm = (tl + tr) >> 1;
        if (i <= tm) {
            update(x, tl, tm, i, v);
        } else {
            update(y, tm + 1, tr, i, v);
        }
        t[id] = merge(t[x], t[y]);
    }

    int get(int id, int tl, int tr, int l, int r) {
        if (r < tl || tr < l) return 0;
        if (l <= tl && tr <= r) return t[id];
        int x = (id << 1) + 1, y = x + 1, tm = (tl + tr) >> 1;
        return merge(get(x, tl, tm, l, r), get(y, tm + 1, tr, l, r));
    }

    void update(int i, int v) { update(0, 0, n - 1, i, v); }
    int get(int l, int r) { return get(0, 0, n - 1, l, r); }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    SegmentTree x(n), y(n);
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            x.update(i, a[i]);
        } else {
            y.update(i, a[i]);
        }
    }
    while (q--) {
        int c, l, r;
        cin >> c >> l >> r;
        if (c == 1) {
            l--;
            if (l % 2 == 0) {
                x.update(l, r);
            } else {
                y.update(l, r);
            }
        } else {
            l--; r--;
            if ((r - l + 1) % 2 == 0) {
                cout << 0 << '\n';
            } else {
                if (l % 2 == 0) {
                    cout << x.get(l, r) << '\n';
                } else {
                    cout << y.get(l, r) << '\n';
                }
            }
        }
    }
    return 0;
}
#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...