답안 #464342

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
464342 2021-08-13T04:05:01 Z tengiz05 XORanges (eJOI19_xoranges) C++17
100 / 100
153 ms 6592 KB
#include <bits/stdc++.h>

using i64 = long long;

struct SegmentTree {
    int n;
    std::vector<int> t;
    SegmentTree(int n) : n(n), t(2 * n) {}
    void modify(int p, int val) {
        for (t[p += n] = val; p > 1; p >>= 1) {
            t[p >> 1] = t[p] ^ t[p ^ 1];
        }
    }
    int get(int l, int r) {
        int res = 0;
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) {
                res ^= t[l++];
            }
            if (r & 1) {
                res ^= t[--r];
            }
        }
        return res;
    }
};

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n, q;
    std::cin >> n >> q;
    
    std::vector<int> a(n);
    SegmentTree s1(n), s2(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        if (i % 2 == 0) {
            s1.modify(i, a[i]);
        } else {
            s2.modify(i, a[i]);
        }
    }
    
    while (q--) {
        int type;
        std::cin >> type;
        if (type == 1) {
            int p, v;
            std::cin >> p >> v;
            p--;
            if (p % 2 == 0) {
                s1.modify(p, v);
            } else {
                s2.modify(p, v);
            }
            a[p] = v;
        } else {
            int l, r;
            std::cin >> l >> r;
            l--;
            if (r - l == 1) {
                std::cout << a[l] << "\n";
            } else if (r - l == 2) {
                std::cout << 0 << "\n";
            } else if (r - l == 3) {
                std::cout << (a[l] ^ a[r - 1]) << "\n";
            } else if ((r - l) % 2 == 0) {
                std::cout << 0 << "\n";
            } else if (l % 2 == 0) {
                std::cout << s1.get(l, r) << "\n";
            } else {
                std::cout << s2.get(l, r) << "\n";
            }
        }
    }
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 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 3 ms 460 KB Output is correct
12 Correct 3 ms 460 KB Output is correct
13 Correct 3 ms 508 KB Output is correct
14 Correct 3 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 6468 KB Output is correct
2 Correct 128 ms 6528 KB Output is correct
3 Correct 136 ms 6592 KB Output is correct
4 Correct 129 ms 6588 KB Output is correct
5 Correct 123 ms 6472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 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 3 ms 460 KB Output is correct
12 Correct 3 ms 460 KB Output is correct
13 Correct 3 ms 508 KB Output is correct
14 Correct 3 ms 460 KB Output is correct
15 Correct 136 ms 6468 KB Output is correct
16 Correct 128 ms 6528 KB Output is correct
17 Correct 136 ms 6592 KB Output is correct
18 Correct 129 ms 6588 KB Output is correct
19 Correct 123 ms 6472 KB Output is correct
20 Correct 127 ms 5948 KB Output is correct
21 Correct 137 ms 5948 KB Output is correct
22 Correct 130 ms 5864 KB Output is correct
23 Correct 126 ms 6504 KB Output is correct
24 Correct 153 ms 6496 KB Output is correct