Submission #759117

# Submission time Handle Problem Language Result Execution time Memory
759117 2023-06-15T19:01:37 Z Pekiban XORanges (eJOI19_xoranges) C++17
100 / 100
111 ms 14008 KB
#include <bits/stdc++.h>

using namespace std;


struct segtree {
    int n;
    int st[800002];
    void build(const vector<int> &v, int i, int l2, int r2) {
        if (l2 == r2) {
            st[i] = v[l2];
            return;
        }
        int m2 = (l2+r2)/2;
        build(v, 2*i, l2, m2);
        build(v, 2*i+1, m2+1, r2);
        st[i] = st[2*i]^st[2*i+1];
    }
    void build(const vector<int> &v) {
        build(v, 1, 0, n-1);
    }
    void update(int l, int x, int i, int l2, int r2) {
        if (l2 == r2) {
            st[i] = x;
            return;
        }
        int m2 = (l2 + r2)/2;
        if (l <= m2) {
            update(l, x, 2*i, l2, m2);
        }
        else {
            update(l, x, 2*i+1, m2+1, r2);
        }
        st[i] = st[2*i]^st[2*i+1];
    }
    void update(int l, int x) {
        update(l, x, 1, 0, n-1);
    }
    int query(int l, int r, int i, int l2, int r2) {
        if (l <= l2 && r2 <= r) {
            return st[i];
        }
        int s = 0;
        int m2 = (l2 + r2)/2;
        if (l <= m2) {
            s^=query(l, r, 2*i, l2, m2);
        }
        if (m2+1 <= r) {
            s^=query(l, r, 2*i+1, m2+1, r2);
        }
        return s;
    }
    int query(int l, int r) {
        return query(l, r, 1, 0, n-1);
    }
};



int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<int> sx(n+3), a(n+3);
    cin >> a[0]; sx[0] = a[0];
    for (int i = 1; i < n; ++i) {
        cin >> a[i];
        if (i%2==0) {
            sx[i] = a[i];
        }
    }
    segtree b, c;
    b.n = n, c.n = n;
    for (int i = 0; i < 800002; ++i) {
        b.st[i] = c.st[i] = 0;
    }
    b.build(sx), c.build(a);
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int l, x;
            cin >> l >> x;
            l--;
            c.update(l, x);
            if (l % 2 == 0) {
                b.update(l, x);
            }
        }
        else {
            int l, r;
            cin >> l >> r;
            l--, r--;
            if ((r-l) %2 ) {
                cout << 0 << '\n';
            }
            else {
                if (l%2 == 0) {
                    cout << b.query(l, r) << '\n';
                }
                else {
                    cout << (b.query(l, r) ^ c.query(l, r)) << '\n';
                }
            }
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 4 ms 6484 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 3 ms 6484 KB Output is correct
5 Correct 3 ms 6484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 4 ms 6484 KB Output is correct
3 Correct 4 ms 6484 KB Output is correct
4 Correct 3 ms 6484 KB Output is correct
5 Correct 3 ms 6484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 4 ms 6484 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 3 ms 6484 KB Output is correct
5 Correct 3 ms 6484 KB Output is correct
6 Correct 3 ms 6484 KB Output is correct
7 Correct 4 ms 6484 KB Output is correct
8 Correct 4 ms 6484 KB Output is correct
9 Correct 3 ms 6484 KB Output is correct
10 Correct 3 ms 6484 KB Output is correct
11 Correct 5 ms 6740 KB Output is correct
12 Correct 5 ms 6740 KB Output is correct
13 Correct 5 ms 6740 KB Output is correct
14 Correct 5 ms 6740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 9340 KB Output is correct
2 Correct 111 ms 9536 KB Output is correct
3 Correct 103 ms 9292 KB Output is correct
4 Correct 96 ms 9300 KB Output is correct
5 Correct 96 ms 9276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 4 ms 6484 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 3 ms 6484 KB Output is correct
5 Correct 3 ms 6484 KB Output is correct
6 Correct 3 ms 6484 KB Output is correct
7 Correct 4 ms 6484 KB Output is correct
8 Correct 4 ms 6484 KB Output is correct
9 Correct 3 ms 6484 KB Output is correct
10 Correct 3 ms 6484 KB Output is correct
11 Correct 5 ms 6740 KB Output is correct
12 Correct 5 ms 6740 KB Output is correct
13 Correct 5 ms 6740 KB Output is correct
14 Correct 5 ms 6740 KB Output is correct
15 Correct 104 ms 9340 KB Output is correct
16 Correct 111 ms 9536 KB Output is correct
17 Correct 103 ms 9292 KB Output is correct
18 Correct 96 ms 9300 KB Output is correct
19 Correct 96 ms 9276 KB Output is correct
20 Correct 106 ms 13896 KB Output is correct
21 Correct 103 ms 13820 KB Output is correct
22 Correct 103 ms 13812 KB Output is correct
23 Correct 98 ms 13776 KB Output is correct
24 Correct 99 ms 14008 KB Output is correct