Submission #638049

# Submission time Handle Problem Language Result Execution time Memory
638049 2022-09-04T12:42:46 Z pakapu XORanges (eJOI19_xoranges) C++14
38 / 100
143 ms 10436 KB
#include <bits/stdc++.h>

using namespace std;

struct segtree {

    struct node {
        long long val;
    };

    vector<node> tree;
    int sz;

    node ZERO = {0};

    node combine(node a, node b) {
        node result;
        result.val = a.val ^ b.val;
        return result;
    }

    void init(int n) {
        sz = 1;
        while(sz < n) {
            sz *= 2;
        }
        tree.assign(2 * sz - 1, ZERO);
    }

    void set(int pos, node val, int x, int lx, int rx) {
        if(rx - lx == 1) {
            tree[x] = val;
            return;
        }

        int mid = (lx + rx) / 2;
        if(pos < mid) {
            set(pos, val, x * 2 + 1, lx, mid);
        }
        else {
            set(pos, val, x * 2 + 2, mid, rx);
        }

        tree[x] = combine(tree[x * 2 + 1], tree[x * 2 + 2]);
    }

    void set(int pos, long long val) {
        node v = {val};
        set(pos, v, 0, 0, sz);
    }

    node get(int l, int r, int x, int lx, int rx) {
        if(l >= rx || lx >= r) {
            return ZERO;
        }
        if(lx >= l && rx <= r) {
            return tree[x];
        }

        int mid = (lx + rx) / 2;
        return combine(get(l, r, x * 2 + 1, lx, mid), get(l, r, x * 2 + 2, mid, rx));
    }

    long long get(int l, int r) {
        return get(l, r + 1, 0, 0, sz).val;
    }

};

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

    int n, q;
    cin >> n >> q;

    segtree sge, sgo;
    sge.init(n / 2 + n % 2);
    sgo.init(n / 2);

    for(int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        if(i % 2 == 1) {
            sgo.set(i / 2, tmp);
        }
        else {
            sge.set(i / 2, tmp);
        }
    }

    while(q--) {
        int x;
        cin >> x;

        if(x == 2) {
            int l, r;
            cin >> l >> r;
            l--;
            r--;
            if((r - l + 1) % 2 == 0) {
                cout << 0 << '\n';
                continue;
            }
            if(l % 2 == 1) {
                cout << sgo.get(l / 2, r / 2) << '\n';
            }
            else {
                cout << sge.get(l / 2, r / 2) << '\n';
            }
        }
        else {
            int i, j;
            cin >> i >> j;
            i--;
            if(i % 2 == 0) {
                sge.set(i, j);
            }
            else {
                sgo.set(i, j);
            }
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 143 ms 5596 KB Output is correct
2 Correct 143 ms 10356 KB Output is correct
3 Correct 125 ms 10436 KB Output is correct
4 Correct 136 ms 10052 KB Output is correct
5 Correct 115 ms 10056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -