답안 #742072

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
742072 2023-05-15T14:38:45 Z bogdanvladmihai XORanges (eJOI19_xoranges) C++14
100 / 100
128 ms 11268 KB
#include <iostream>
#include <vector>

std::vector<int> tree[2];

void build(int p, int u, const std::vector<int> &V, int l, int r) {
    if (l == r) {
        tree[p][u] = V[l];
        return;
    }
    int m = (l + r) / 2;
    build(p, 2 * u, V, l, m);
    build(p, 2 * u + 1, V, m + 1, r);
    tree[p][u] = tree[p][2 * u] ^ tree[p][2 * u + 1];
}

void update(int p, int u, int l, int r, int pos, int val) {
    if (l == r) {
        tree[p][u] = val;
        return;
    }
    int m = (l + r) / 2;
    if (pos <= m) {
        update(p, 2 * u, l, m, pos, val);
    } else {
        update(p, 2 * u + 1, m + 1, r, pos, val);
    }
    tree[p][u] = tree[p][2 * u] ^ tree[p][2 * u + 1];
}

int query(int p, int u, int l, int r, int ql, int qr) {
    if (ql <= l && r <= qr) {
        return tree[p][u];
    }
    int m = (l + r) / 2;
    int lSide = 0, rSide = 0;
    if (ql <= m) {
        lSide = query(p, 2 * u, l, m, ql, qr);
    }
    if (qr > m) {
        rSide = query(p, 2 * u + 1, m + 1, r, ql, qr);
    }
    return lSide ^ rSide;
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

    int N, Q;
    std::cin >> N >> Q;
    std::vector<int> V(N);
    for (int &x : V) {
        std::cin >> x;
    }
    std::vector<int> A, B;
    for (int i = 0; i < N; i++) {
        (i % 2 == 0 ? A : B).push_back(V[i]);
    }
    tree[0].resize(4 * A.size());
    tree[1].resize(4 * B.size());
    build(0, 1, A, 0, A.size() - 1);
    build(1, 1, B, 0, B.size() - 1);

    for (int q = 0; q < Q; q++) {
        int op, a, b;
        std::cin >> op >> a >> b;
        a--;
        b--;
        int size = (a % 2 == 0 ? A.size() : B.size()) - 1;
        if (op == 1) {
            update(a % 2, 1, 0, size, a / 2, b + 1);
        } else {
            std::cout << ((b - a) % 2 == 1 ? 0 :
                          query(a % 2, 1, 0, size, a / 2, b / 2)) << "\n";
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 252 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 252 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 588 KB Output is correct
12 Correct 4 ms 596 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 3 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 128 ms 6692 KB Output is correct
2 Correct 118 ms 11188 KB Output is correct
3 Correct 114 ms 11268 KB Output is correct
4 Correct 111 ms 10940 KB Output is correct
5 Correct 125 ms 10920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 252 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 588 KB Output is correct
12 Correct 4 ms 596 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 3 ms 592 KB Output is correct
15 Correct 128 ms 6692 KB Output is correct
16 Correct 118 ms 11188 KB Output is correct
17 Correct 114 ms 11268 KB Output is correct
18 Correct 111 ms 10940 KB Output is correct
19 Correct 125 ms 10920 KB Output is correct
20 Correct 112 ms 10936 KB Output is correct
21 Correct 114 ms 10944 KB Output is correct
22 Correct 123 ms 10884 KB Output is correct
23 Correct 118 ms 10924 KB Output is correct
24 Correct 109 ms 10936 KB Output is correct