Submission #675662

# Submission time Handle Problem Language Result Execution time Memory
675662 2022-12-27T16:50:36 Z Alma XORanges (eJOI19_xoranges) C++17
0 / 100
489 ms 6352 KB
#include <bits/stdc++.h>
using namespace std;

void build(vector<int>& segTree, vector<int>& a, int x, int l, int r) {
    if (l == r) {
        segTree[x] = a[l];
        return;
    }
    int mid = (l+r)/2;
    build(segTree, a, 2*x, l, mid);
    build(segTree, a, 2*x+1, mid+1, r);
    segTree[x] = segTree[2*x] ^ segTree[2*x+1];
}

void update(vector<int>& segTree, vector<int>& a, int x, int l, int r, int i, int v) {
    if (l == r) {
        segTree[x] = a[l] = v;
        return;
    }
    int mid = (l+r)/2;
    if (i <= mid) {
        update(segTree, a, 2*x, l, mid, i, v);
    } else{
        update(segTree, a, 2*x+1, mid+1, r, i, v);
    }
    segTree[x] = segTree[2*x] ^ segTree[2*x+1];
}

int getRange(vector<int>& segTree, int x, int l, int r, int lb, int rb) {
    if (rb <= l or r <= lb) {
        return 0;
    } else if (lb <= l and r <= rb) {
        return segTree[x];
    } else {
        int mid = (l+r)/2;
        int xor1 = getRange(segTree, 2*x, l, mid, lb, rb);
        int xor2 = getRange(segTree, 2*x+1, mid+1, r, lb, rb);
        return xor1 ^ xor2;
    }
}

int main() {
    // ios::sync_with_stdio(false);
    // cin.tie(NULL);
    
    int n, n1, n2, q;
    vector<int> a, a1, a2;
    vector<int> segTree1, segTree2;
    int type, pos, val, l, r;

    cin >> n >> q;
    a = vector<int>(n);
    for (int& i: a) cin >> i;

    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            a1.push_back(a[i]);
        } else {
            a2.push_back(a[i]);
        }
    }
    n1 = a1.size();
    n2 = a2.size();
    
    segTree1 = vector<int>(4*n1, 0);
    segTree2 = vector<int>(4*n2, 0);
    build(segTree1, a1, 1, 0, n1-1);
    build(segTree2, a2, 1, 0, n2-1);

    while (q--) {
        cin >> type;

        if (type == 1) { // rescan
            cin >> pos >> val;
            pos--;
            a[pos] = val;
            int idx = pos/2;
            if (pos % 2 == 0) {
                update(segTree1, a1, 1, 0, n1-1, idx, val);
            } else {
                update(segTree2, a2, 1, 0, n2-1, idx, val);
            }
        } 
        
        else { // query
            cin >> l >> r;
            l--; r--;
            int range = r-l+1;
            if (l == r) {
                cout << a[l] << '\n';
            } else if (range % 2 == 0) {
                cout << "0\n";
            } else {
                if (l % 2 == 0) {
                    cout << getRange(segTree1, 1, 0, n1-1, l/2, r/2) << '\n';
                } else {
                    cout << getRange(segTree2, 1, 0, n2-1, l/2, r/2) << '\n';
                }
            }
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 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 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 489 ms 6352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -