Submission #1338987

#TimeUsernameProblemLanguageResultExecution timeMemory
1338987DangKhoizzzzXORanges (eJOI19_xoranges)C++20
100 / 100
163 ms10996 KiB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 10;

struct node
{
    int sumxor[2] , cnt;
    node() {sumxor[0] = sumxor[1] = cnt = 0;}
};
int n , q;
node st[maxn*4];

node join(node l , node r)
{
    node res;
    res.cnt = l.cnt + r.cnt;
    if(l.cnt&1) swap(r.sumxor[0] , r.sumxor[1]);
    res.sumxor[0] = (l.sumxor[0]^ r.sumxor[0]);
    res.sumxor[1] = (l.sumxor[1]^ r.sumxor[1]);
    return res;
}
void update(int id , int l , int r , int pos , int val)
{
    if(r < pos || l > pos) return;
    if(l == r)
    {
        st[id].cnt = 1; st[id].sumxor[0] = 0; st[id].sumxor[1] = val;
        return;
    }
    int mid = (l+r)>>1;
    update(id*2 , l , mid , pos , val);
    update(id*2+1, mid+1, r , pos , val);
    st[id] = join(st[id*2] , st[id*2+1]);
}
node get(int id , int l , int r , int u , int v)
{
    if(r < u || l > v) return node();
    if(u <= l && r <= v) return st[id];
    int mid = (l+r)>>1;
    return join(get(id*2,l,mid,u,v) , get(id*2+1,mid+1,r,u,v));
}

void solve()
{
    cin >> n >> q;
    for(int i = 1; i <= n; i++) 
    {
        int x; cin >> x; update(1 , 1 , n , i , x);
    }
    while(q--)
    {
        int t , x , y; cin >> t >> x >> y;
        if(t == 1) update(1 , 1 , n , x , y);
        else
        {
            node res = get(1 , 1 , n , x , y);
            if((y-x+1)&1) cout << res.sumxor[1] << '\n';
            else cout << 0 << '\n';
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    solve();
    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...