Submission #433742

# Submission time Handle Problem Language Result Execution time Memory
433742 2021-06-20T10:11:26 Z Valaki2 XORanges (eJOI19_xoranges) C++14
100 / 100
211 ms 10240 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, vl, mid, ql, min(mid, qr)) ^
        combine_odd(v * 2 + 1, mid + 1, vr, max(mid + 1, ql), 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, vl, mid, ql, min(mid, qr)) ^
        combine_even(v * 2 + 1, mid + 1, vr, max(mid + 1, ql), 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 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 4 ms 452 KB Output is correct
12 Correct 4 ms 452 KB Output is correct
13 Correct 4 ms 460 KB Output is correct
14 Correct 5 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 190 ms 5384 KB Output is correct
2 Correct 201 ms 10240 KB Output is correct
3 Correct 204 ms 10208 KB Output is correct
4 Correct 188 ms 9852 KB Output is correct
5 Correct 174 ms 9896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 4 ms 452 KB Output is correct
12 Correct 4 ms 452 KB Output is correct
13 Correct 4 ms 460 KB Output is correct
14 Correct 5 ms 460 KB Output is correct
15 Correct 190 ms 5384 KB Output is correct
16 Correct 201 ms 10240 KB Output is correct
17 Correct 204 ms 10208 KB Output is correct
18 Correct 188 ms 9852 KB Output is correct
19 Correct 174 ms 9896 KB Output is correct
20 Correct 201 ms 9984 KB Output is correct
21 Correct 202 ms 9988 KB Output is correct
22 Correct 210 ms 9980 KB Output is correct
23 Correct 211 ms 9864 KB Output is correct
24 Correct 199 ms 9892 KB Output is correct