Submission #345946

# Submission time Handle Problem Language Result Execution time Memory
345946 2021-01-08T14:19:37 Z iliccmarko XORanges (eJOI19_xoranges) C++14
100 / 100
179 ms 11372 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define INF 1000000000
#define LINF 1000000000000000LL
#define pb push_back
#define all(x) x.begin(), x.end()
#define len(s) (int)s.size()
#define test_case { int t; cin>>t; while(t--)solve(); }
#define single_case solve();
#define line cerr<<"----------"<<endl;
#define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL); }
#define mod 1000000007LL
const int N = 2e5 + 5;
int segp[4*N], segn[4*N];
int n;
int a[N];

int buildp(int node, int l, int r)
{
    if(l==r)
    {
        if(l%2==1) return 0;
        return segp[node] = a[l];
    }
    int mid = (l+r)/2;
    return segp[node] = buildp(node*2+1, l, mid)^buildp(node*2+2, mid+1, r);
}

int buildn(int node, int l, int r)
{
    if(l==r)
    {
        if(l%2==0) return 0;
        return segn[node] = a[l];
    }
    int mid = (l+r)/2;
    return segn[node] = buildn(node*2+1, l, mid)^buildn(node*2+2, mid+1, r);
}

void updatep(int node, int l, int r, int pos, int x)
{
    if(l==r)
    {
        segp[node] = x;
        return;
    }
    int mid = (l+r)/2;
    if(pos>mid) updatep(node*2+2, mid+1, r, pos, x);
    else updatep(node*2+1, l, mid, pos, x);
    segp[node] = segp[node*2+1]^segp[node*2+2];
}

void updaten(int node, int l, int r, int pos, int x)
{
    if(l==r)
    {
        //cout<<"posatavio "<<pos<<" na"<<x<<endl;
        segn[node] = x;
        return;
    }
    int mid = (l+r)/2;
    if(pos>mid) updaten(node*2+2, mid+1, r, pos, x);
    else updaten(node*2+1, l, mid, pos, x);
    segn[node] = segn[node*2+1]^segn[node*2+2];
    //cerr<<l<<"      "<<r<<"          "<<segn[node]<<endl;
}

int get_xor(int node, int l, int r, int i, int j, int tip)
{
    if(i>r||j<l) return 0;
    if(i>=l&&j<=r)
    {
        if(tip==1) return segp[node];
        else {
            return segn[node];
        }
    }
    int mid = (i+j)/2;
    return get_xor(node*2+1, l, r, i, mid, tip)^get_xor(node*2+2, l, r, mid+1, j, tip);
}

int main()
{
    ios
    int q;
    cin>>n>>q;
    for(int i = 1;i<=n;i++)
    {
        cin>>a[i];
    }
    buildn(0, 1, n);
    buildp(0, 1, n);


    while(q--)
    {
        int t;
        cin>>t;
        if(t==1)
        {
            int ind, val;
            cin>>ind>>val;
            if(ind%2==1) updaten(0, 1, n, ind, val); //cerr<<ind<<" "<<val<<endl;
            else updatep(0, 1, n, ind, val);
        }
        else
        {
            int l, r;
            cin>>l>>r;
            if((r-l+1)%2==0)
            {
                cout<<0<<endl;
            }
            else
            {
                if(l%2==1)
                {
                    //cout<<get_xor(0, 3, 3, 1, n, 2)<<" usao"<<endl;
                    cout<<get_xor(0, l, r, 1, n, 2)<<endl;
                }
                else
                {
                    cout<<get_xor(0, l, r, 1, n, 1)<<endl;
                }
            }
        }
    }




    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 4 ms 620 KB Output is correct
12 Correct 4 ms 620 KB Output is correct
13 Correct 4 ms 620 KB Output is correct
14 Correct 4 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 162 ms 11244 KB Output is correct
2 Correct 165 ms 11280 KB Output is correct
3 Correct 179 ms 11372 KB Output is correct
4 Correct 137 ms 10988 KB Output is correct
5 Correct 139 ms 10988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 4 ms 620 KB Output is correct
12 Correct 4 ms 620 KB Output is correct
13 Correct 4 ms 620 KB Output is correct
14 Correct 4 ms 620 KB Output is correct
15 Correct 162 ms 11244 KB Output is correct
16 Correct 165 ms 11280 KB Output is correct
17 Correct 179 ms 11372 KB Output is correct
18 Correct 137 ms 10988 KB Output is correct
19 Correct 139 ms 10988 KB Output is correct
20 Correct 154 ms 10988 KB Output is correct
21 Correct 159 ms 10988 KB Output is correct
22 Correct 153 ms 11116 KB Output is correct
23 Correct 138 ms 10988 KB Output is correct
24 Correct 139 ms 11064 KB Output is correct