46462023-03-30 14:07:46gortomiXORangescpp17Accepted 100/100210ms22724 KiB
#include <bits/stdc++.h>
using namespace std;
vector<int> even, odd;
void upd(int v, int l, int r, int x, int val)
{
    if(l == r)
    {
        if(l % 2 == 0)
        {
            even[v] = val;
            odd[v] = 0;
        }
        else
        {
            even[v] = 0;
            odd[v] = val;
        }
        return;
    }
    int m = (l + r) / 2;
    if(x <= m) upd(v * 2, l, m, x, val);
    else upd(v * 2 + 1, m + 1, r, x, val);
    odd[v] = odd[v * 2] ^ odd[v * 2 + 1];
    even[v] = even[v * 2] ^ even[v * 2 + 1];
}
int get(int v, int l, int r, int tl, int tr, int type)
{
    if(tl > tr) return 0;
    if(tl == l && tr == r) return type == 0 ? even[v] : odd[v];
    int m = (l + r) / 2;
    return get(v * 2, l, m, tl, min(tr, m), type) ^ get(v * 2 + 1, m + 1, r, max(tl, m + 1), tr, type);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    int s;
    for(int i = 0; i <= 30; i++)
    {
        if((1 << i) >= n)
        {
            s = 1 << i;
            break;
        }
    }
    even.resize(4 * s);
    odd.resize(4 * s);
    vector<int> a(s + 1);
    for(int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        a[i] = x;
        upd(1, 1, s, i, x);
    }
    while(q--)
    {
        int type, l, r;
        cin >> type >> l >> r;
        if(type == 1)
        {
            upd(1, 1, s, l, r);
            a[l] = r;
        }
        if(type == 2)
        {
            cout << ((l - r + 1) % 2 == 0 ? 0 : get(1, 1, s, l, r, l % 2)) << "\n";
        }
    }
}
SubtaskSumTestVerdictTimeMemory
subtask112/12
1Accepted3ms1832 KiB
2Accepted3ms2052 KiB
3Accepted3ms2268 KiB
4Accepted3ms2452 KiB
5Accepted3ms2820 KiB
subtask218/18
1Accepted3ms3152 KiB
2Accepted3ms3152 KiB
3Accepted3ms3224 KiB
4Accepted3ms3436 KiB
5Accepted3ms3536 KiB
subtask325/25
1Accepted7ms4256 KiB
2Accepted7ms4264 KiB
3Accepted7ms4260 KiB
4Accepted7ms4500 KiB
subtask420/20
1Accepted209ms22256 KiB
2Accepted209ms22256 KiB
3Accepted210ms22292 KiB
4Accepted201ms22592 KiB
5Accepted199ms22720 KiB
subtask525/25
1Accepted202ms22724 KiB
2Accepted202ms22720 KiB
3Accepted203ms22724 KiB
4Accepted199ms22724 KiB
5Accepted201ms22724 KiB