Submission #1096623

# Submission time Handle Problem Language Result Execution time Memory
1096623 2024-10-04T22:34:51 Z Ariadna XORanges (eJOI19_xoranges) C++14
100 / 100
382 ms 13400 KB
#include <bits/stdc++.h>

using namespace std;

struct Segtree {
    int n, d;
    vector<int> st;
    
    Segtree(const vector<int>& a, int c) {
        n = (int)a.size();
        st = vector<int>(4*n);
        d = c;
        build(1, 0, n-1, a);
    }

    void build(int p, int l, int r, const vector<int>& a) {
        if (l == r) {
            if (l%2 == d) st[p] = a[l];
            else st[p] = 0; 
        } else {
            int m = (l+r)/2;
            build(2*p, l, m, a);
            build(2*p+1, m+1, r, a);
            st[p] = st[2*p]^st[2*p+1];
        }
    } 

    void change(int p, int l, int r, int i, int x) {
        if (l == r) {
            if (l%2 == d) st[p] = x;
            else st[p] = 0;
        } else {
            int m = (l+r)/2;
            if (i <= m) change(2*p, l, m, i, x);
            else change(2*p+1, m+1, r, i, x);
            st[p] = st[2*p]^st[2*p+1];
        }
    }

    int Xor(int p, int l, int r, int i, int j) {
        if (i > j) return 0;
        if (i == l && j == r) return st[p];
        int m = (l+r)/2;
        return Xor(2*p, l, m, i, min(m, j))^Xor(2*p+1, m+1, r, max(i, m+1), j);
    }

    void change(int i, int x) { change(1, 0, n-1, i, x); }
    int Xor(int i, int j) { return Xor(1, 0, n-1, i, j); }
};

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    Segtree St0(a, 0), St1(a, 1);

    while (q--) {
        int t; cin >> t;
        if (t == 1) {
            int p, x; cin >> p >> x;
            --p;
            if (p%2) St1.change(p, x);
            else St0.change(p, x);
        } else {
            int l, r; cin >> l >> r; --l; --r;
            if ((r-l+1)%2) {
                if (l%2) cout << St1.Xor(l, r) << endl;
                else cout << St0.Xor(l, r) << endl;
            } else cout << 0 << endl;
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 7 ms 600 KB Output is correct
12 Correct 7 ms 604 KB Output is correct
13 Correct 10 ms 732 KB Output is correct
14 Correct 9 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 373 ms 13400 KB Output is correct
2 Correct 369 ms 13348 KB Output is correct
3 Correct 382 ms 13392 KB Output is correct
4 Correct 355 ms 13140 KB Output is correct
5 Correct 372 ms 12984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 7 ms 600 KB Output is correct
12 Correct 7 ms 604 KB Output is correct
13 Correct 10 ms 732 KB Output is correct
14 Correct 9 ms 604 KB Output is correct
15 Correct 373 ms 13400 KB Output is correct
16 Correct 369 ms 13348 KB Output is correct
17 Correct 382 ms 13392 KB Output is correct
18 Correct 355 ms 13140 KB Output is correct
19 Correct 372 ms 12984 KB Output is correct
20 Correct 302 ms 13104 KB Output is correct
21 Correct 291 ms 13140 KB Output is correct
22 Correct 276 ms 13140 KB Output is correct
23 Correct 356 ms 13140 KB Output is correct
24 Correct 360 ms 12984 KB Output is correct