답안 #446158

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
446158 2021-07-21T07:08:15 Z omg XORanges (eJOI19_xoranges) C++17
100 / 100
642 ms 11192 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 288 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 2 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 288 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 2 ms 204 KB Output is correct
11 Correct 12 ms 620 KB Output is correct
12 Correct 12 ms 632 KB Output is correct
13 Correct 17 ms 588 KB Output is correct
14 Correct 18 ms 616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 637 ms 11192 KB Output is correct
2 Correct 633 ms 11132 KB Output is correct
3 Correct 642 ms 11132 KB Output is correct
4 Correct 619 ms 10824 KB Output is correct
5 Correct 617 ms 10924 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 288 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 2 ms 204 KB Output is correct
11 Correct 12 ms 620 KB Output is correct
12 Correct 12 ms 632 KB Output is correct
13 Correct 17 ms 588 KB Output is correct
14 Correct 18 ms 616 KB Output is correct
15 Correct 637 ms 11192 KB Output is correct
16 Correct 633 ms 11132 KB Output is correct
17 Correct 642 ms 11132 KB Output is correct
18 Correct 619 ms 10824 KB Output is correct
19 Correct 617 ms 10924 KB Output is correct
20 Correct 490 ms 11000 KB Output is correct
21 Correct 473 ms 10940 KB Output is correct
22 Correct 478 ms 10940 KB Output is correct
23 Correct 592 ms 10876 KB Output is correct
24 Correct 606 ms 10932 KB Output is correct