답안 #761163

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
761163 2023-06-19T09:53:46 Z LucaLucaM XORanges (eJOI19_xoranges) C++17
100 / 100
76 ms 7924 KB
#include <bits/stdc++.h>

using namespace std;

const int NMAX = 2e5;

int a[NMAX + 5];

struct FenwickTree
{
    int n;
    vector<int>aib;
    void build (int _n)
    {
        n = _n + 1;
        aib.resize(n, 0);
    }
    void update (int pos, int val)
    {
        for (; pos < n; pos += pos & -pos)
            aib[pos] ^= val;
    }
    int query (int pos)
    {
        int ret = 0;
        for (; pos > 0; pos -= pos & -pos)
            ret ^= aib[pos];
        return ret;
    }
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, q;
    cin >> n >> q;
    FenwickTree aib[2];
    aib[0].build(n / 2 + 1);
    aib[1].build(n / 2 + 1);
    for (int i=2; i<=n+1; i++)
    {
        cin >> a[i];
        aib[i & 1].update(i / 2, a[i]);
    }
    while (q--)
    {
        int op, x, y;
        cin >> op >> x >> y;
        x++;
        if (op == 1)
        {
            int v = (a[x] ^ y);
            aib[x & 1].update(x / 2, v);
            a[x] = y;
        }
        else
        {
            y++;
            int ans = 0;
            if (x % 2 != y % 2)
            {
                cout << "0\n";
                continue;
            }
            if (x % 2 == 0)
            {
                x /= 2, y /= 2;
                cout << (aib[0].query(y) ^ aib[0].query(x - 1)) << '\n';
            }
            else
            {
                x /= 2, y /= 2;
                cout << (aib[1].query(y) ^ aib[1].query(x - 1)) << '\n';
            }
        }
    }
    return 0;
}

Compilation message

xoranges.cpp: In function 'int main()':
xoranges.cpp:61:17: warning: unused variable 'ans' [-Wunused-variable]
   61 |             int ans = 0;
      |                 ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 240 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 240 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 5172 KB Output is correct
2 Correct 64 ms 7872 KB Output is correct
3 Correct 64 ms 7924 KB Output is correct
4 Correct 62 ms 7584 KB Output is correct
5 Correct 62 ms 7548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 240 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 65 ms 5172 KB Output is correct
16 Correct 64 ms 7872 KB Output is correct
17 Correct 64 ms 7924 KB Output is correct
18 Correct 62 ms 7584 KB Output is correct
19 Correct 62 ms 7548 KB Output is correct
20 Correct 69 ms 7596 KB Output is correct
21 Correct 76 ms 7548 KB Output is correct
22 Correct 63 ms 7632 KB Output is correct
23 Correct 71 ms 7528 KB Output is correct
24 Correct 62 ms 7516 KB Output is correct