제출 #778351

#제출 시각아이디문제언어결과실행 시간메모리
778351andrei_iorgulescuXORanges (eJOI19_xoranges)C++14
55 / 100
4 ms596 KiB
#include <bits/stdc++.h>

using namespace std;

int n,q;
int aintpar[200005];
int aintimpar[200005];

void update(int nod,int l,int r,int pos,int val)
{
    if (l == r)
    {
        if (l % 2 == 1)
            aintimpar[nod] = val;
        else
            aintpar[nod] = val;
        return;
    }
    int mij = (l + r) / 2;
    if (pos <= mij)
        update(2 * nod,l,mij,pos,val);
    else
        update(2 * nod + 1,mij + 1,r,pos,val);
    aintpar[nod] = aintpar[2 * nod] ^ aintpar[2 * nod + 1];
    aintimpar[nod] = aintimpar[2 * nod] ^ aintimpar[2 * nod + 1];
}

int querypar(int nod,int l,int r,int st,int dr)
{
    if (r < st or dr < l)
        return 0;
    if (st <= l and r <= dr)
        return aintpar[nod];
    int mij = (l + r) / 2;
    return querypar(2 * nod,l,mij,st,dr) ^ querypar(2 * nod + 1,mij + 1,r,st,dr);
}

int queryimpar(int nod,int l,int r,int st,int dr)
{
    if (r < st or dr < l)
        return 0;
    if (st <= l and r <= dr)
        return aintimpar[nod];
    int mij = (l + r) / 2;
    return queryimpar(2 * nod,l,mij,st,dr) ^ queryimpar(2 * nod + 1,mij + 1,r,st,dr);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> q;
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        update(1,1,n,i,x);
    }
    for (int i = 1; i <= q; i++)
    {
        int tip,x,y;
        cin >> tip >> x >> y;
        if (tip == 1)
            update(1,1,n,x,y);
        else
        {
            if (y % 2 != x % 2)
                cout << 0 << '\n';
            else if (x % 2 == 0)
                cout << querypar(1,1,n,x,y) << '\n';
            else
                cout << queryimpar(1,1,n,x,y) << '\n';
        }
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...