Submission #433728

# Submission time Handle Problem Language Result Execution time Memory
433728 2021-06-20T10:03:48 Z Valaki2 XORanges (eJOI19_xoranges) C++14
0 / 100
141 ms 10164 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int n, q;
vector<int> numbers;

vector<int> segtree_even;
vector<int> segtree_odd;
int even_size;
int odd_size;

void update_odd(int v, int vl, int vr, int pos, int val) {
    if(vl == vr) {
        segtree_odd[v] = val;
        return;
    }
    int mid = (vl + vr) / 2;
    if(pos <= mid) {
        update_odd(2 * v, vl, mid, pos, val);
    } else {
        update_odd(2 * v + 1, mid + 1, vr, pos, val);
    }
    segtree_odd[v] = (segtree_odd[2 * v] ^ segtree_odd[2 * v + 1]);
}

void update_even(int v, int vl, int vr, int pos, int val) {
    if(vl == vr) {
        segtree_even[v] = val;
        return;
    }
    int mid = (vl + vr) / 2;
    if(pos <= mid) {
        update_even(2 * v, vl, mid, pos, val);
    } else {
        update_even(2 * v + 1, mid + 1, vr, pos, val);
    }
    segtree_even[v] = (segtree_even[2 * v] ^ segtree_even[2 * v + 1]);
}

int combine_odd(int v, int vl, int vr, int ql, int qr) {
    if(qr < ql) return 0;
    if(ql == vl && qr == vr) return segtree_odd[v];
    int mid = (vl + vr) / 2;
    return (combine_odd(v * 2, max(vl, ql), mid, ql, mid) ^
        combine_odd(v * 2 + 1, mid + 1, min(vr, qr), mid + 1, qr));
}

int combine_even(int v, int vl, int vr, int ql, int qr) {
    if(qr < ql) return 0;
    if(ql == vl && qr == vr) return segtree_even[v];
    int mid = (vl + vr) / 2;
    return (combine_even(v * 2, max(vl, ql), mid, ql, mid) ^
        combine_even(v * 2 + 1, mid + 1, min(vr, qr), mid + 1, qr));
}

void update() {
    int pos, val;
    cin >> pos >> val;
    numbers[pos] = val;
    if(pos % 2 == 1)
        update_odd(1, 1, odd_size, (pos + 1) / 2, val);
    else
        update_even(1, 1, even_size, (pos) / 2, val);
}

void query() {
    int l, r;
    cin >> l >> r;
    if((r - l + 1) % 2 == 0) {
        cout << "0\n";
        return;
    }
    if(l % 2 == 1)
        cout << combine_odd(1, 1, odd_size, (l + 1) / 2, (r + 1) / 2) << "\n";
    else
        cout << combine_even(1, 1, even_size, l / 2, r / 2) << "\n";
}

void solve() {
    cin >> n >> q;
    numbers.assign(1 + n, 0);
    even_size = n / 2;
    odd_size = (n + 1) / 2;
    segtree_even.assign(1 + 4 * even_size, 0);
    segtree_odd.assign(1 + 4 * odd_size, 0);
    for(int i = 1; i <= n; ++i) {
        cin >> numbers[i];
        if(i % 2 == 1) {
            update_odd(1, 1, odd_size, (i + 1) / 2, numbers[i]);
        } else {
            update_even(1, 1, even_size, i / 2, numbers[i]);
        }
    }
    while(q--) {
        int type = 0;
        cin >> type;
        if(type == 1) update();
        else query();
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 141 ms 10164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -