Submission #759813

# Submission time Handle Problem Language Result Execution time Memory
759813 2023-06-16T20:40:21 Z ivaziva XORanges (eJOI19_xoranges) C++14
100 / 100
471 ms 16836 KB
#include <bits/stdc++.h>

using namespace std;

#define MAXN 200010

long long n;
long long q;
long long niz[MAXN];
long long segment[4*MAXN];
queue<pair<long long,long long>> neparni;
queue<pair<long long,long long>> parni;
long long mesta[MAXN];

void build(long long node,long long l,long long r)
{
    if (l==r) segment[node]=niz[l];
    else
    {
        long long mid=(l+r)/2;
        build(2*node,l,mid);
        build(2*node+1,mid+1,r);
        segment[node]=segment[2*node]^segment[2*node+1];
    }
}

void update(long long node,long long l,long long r,long long pos,long long val)
{
    if (l==r) segment[node]=val;
    else
    {
        long long mid=(l+r)/2;
        if (pos<=mid) update(2*node,l,mid,pos,val);
        else update(2*node+1,mid+1,r,pos,val);
        segment[node]=segment[2*node]^segment[2*node+1];
    }
}

long long sol(long long node,long long l,long long r,long long a,long long b)
{
    if (a>b) return 0;
    if (l==a and r==b) return segment[node];
    long long mid=(l+r)/2;
    return sol(2*node,l,mid,a,min(mid,b))^sol(2*node+1,mid+1,r,max(mid+1,a),b);
}

int main()
{
    cin>>n>>q;
    for (long long i=1;i<=n;i++)
    {
        long long x;
        cin>>x;
        if (i%2==0) parni.push({x,i});
        else neparni.push({x,i});
    }
    long long pos=1;
    while (neparni.empty()==false)
    {
        niz[pos]=neparni.front().first;
        mesta[neparni.front().second]=pos;
        neparni.pop();
        pos++;
    }
    while (parni.empty()==false)
    {
        niz[pos]=parni.front().first;
        mesta[parni.front().second]=pos;
        parni.pop();
        pos++;
    }
    build(1,1,n);
    /*for (long long i=1;i<=n;i++) cout<<niz[i]<<" ";
    cout<<endl;
    for (long long i=1;i<=n;i++) cout<<mesta[i]<<" ";
    cout<<endl;*/
    for (long long i=1;i<=q;i++)
    {
        long long t;
        cin>>t;
        long long a;
        long long b;
        cin>>a>>b;
        if (t==1) update(1,1,n,mesta[a],b);
        else
        {
            //cout<<mesta[a]<<" "<<mesta[b]<<endl;
            if ((b-a+1)%2==1) cout<<sol(1,1,n,mesta[a],mesta[b])<<endl;
            else cout<<0<<endl;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 8 ms 744 KB Output is correct
12 Correct 8 ms 724 KB Output is correct
13 Correct 15 ms 756 KB Output is correct
14 Correct 10 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 455 ms 16800 KB Output is correct
2 Correct 440 ms 16836 KB Output is correct
3 Correct 471 ms 16784 KB Output is correct
4 Correct 435 ms 16516 KB Output is correct
5 Correct 412 ms 16528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 8 ms 744 KB Output is correct
12 Correct 8 ms 724 KB Output is correct
13 Correct 15 ms 756 KB Output is correct
14 Correct 10 ms 724 KB Output is correct
15 Correct 455 ms 16800 KB Output is correct
16 Correct 440 ms 16836 KB Output is correct
17 Correct 471 ms 16784 KB Output is correct
18 Correct 435 ms 16516 KB Output is correct
19 Correct 412 ms 16528 KB Output is correct
20 Correct 373 ms 16512 KB Output is correct
21 Correct 337 ms 16592 KB Output is correct
22 Correct 340 ms 16596 KB Output is correct
23 Correct 415 ms 16472 KB Output is correct
24 Correct 410 ms 16540 KB Output is correct