답안 #439129

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
439129 2021-06-29T09:11:10 Z elazarkoren XORanges (eJOI19_xoranges) C++17
100 / 100
704 ms 11220 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;

struct Seg{
    vi seg;
    int n;
    Seg(int m) {
        for (n = 1; n < m; n <<= 1);
        seg.resize(2 * n);
    }
    void update(int i, int x) {
        seg[i += n] = x;
        for (i >>= 1; i; i >>= 1) seg[i] = seg[2 * i] ^ seg[2 * i + 1];
    }
    int query(int l, int r) {
        int ans = 0;
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) ans ^= seg[l++];
            if (r & 1) ans ^= seg[--r];
        }
        return ans;
    }
};

int main() {
    int n, q;
    cin >> n >> q;
    vi a(n + 1);
    vector<Seg> seg(2, Seg(n + 1));
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        seg[i & 1].update(i, a[i]);
    }
    while (q--) {
        int type;
        cin >> type;
        if (type == 1) {
            int i, x;
            cin >> i >> x;
            seg[i & 1].update(i, x);
            continue;
        }
        int l, r;
        cin >> l >> r;
        if (!((r - l + 1) & 1)) {
            cout << 0 << '\n';
            continue;
        }
        cout << seg[(l & 1)].query(l, r + 1) << '\n';
//        int ans = 0;
//        for (int i = 1; i <= r - l + 1; i++) {
//            for (int j = l; j + i - 1 <= r; j++) {
//                for (int k = j; k < j + i; k++) {
//                    ans ^= a[k];
//                }
//            }
//        }
//        cout << ans << '\n';
    }
}
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 2 ms 204 KB Output is correct
5 Correct 3 ms 204 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 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 2 ms 204 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 2 ms 204 KB Output is correct
10 Correct 3 ms 204 KB Output is correct
11 Correct 12 ms 560 KB Output is correct
12 Correct 12 ms 716 KB Output is correct
13 Correct 17 ms 588 KB Output is correct
14 Correct 16 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 698 ms 9016 KB Output is correct
2 Correct 675 ms 11164 KB Output is correct
3 Correct 704 ms 11220 KB Output is correct
4 Correct 618 ms 10776 KB Output is correct
5 Correct 626 ms 10816 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 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 2 ms 204 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 2 ms 204 KB Output is correct
10 Correct 3 ms 204 KB Output is correct
11 Correct 12 ms 560 KB Output is correct
12 Correct 12 ms 716 KB Output is correct
13 Correct 17 ms 588 KB Output is correct
14 Correct 16 ms 620 KB Output is correct
15 Correct 698 ms 9016 KB Output is correct
16 Correct 675 ms 11164 KB Output is correct
17 Correct 704 ms 11220 KB Output is correct
18 Correct 618 ms 10776 KB Output is correct
19 Correct 626 ms 10816 KB Output is correct
20 Correct 487 ms 10932 KB Output is correct
21 Correct 499 ms 11084 KB Output is correct
22 Correct 511 ms 11020 KB Output is correct
23 Correct 616 ms 10872 KB Output is correct
24 Correct 603 ms 10848 KB Output is correct