답안 #637414

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
637414 2022-09-01T16:30:47 Z ulianamalanyak XORanges (eJOI19_xoranges) C++14
100 / 100
130 ms 11220 KB
#include <bits/stdc++.h>

using namespace std;

#define endl "\n"
#define INF 1e16
#define fi first
#define se second
#define pb push_back
#define in insert
#define speedup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

//--------------------------------|
const int DIM=2e5+7;

ll n,m,k,l,r,q,t;
ll a[DIM];
ll Tf[4*DIM];
ll Ts[4*DIM];

//--------------------------------|

void buildf(ll l, ll r, ll v)
{
    if (l==r)
    {
        if (l%2==0)
        {
            Tf[v]=0;
        }
        else
        {
            Tf[v]=a[l];
        }
        return;
    }

    ll mid=(l+r)/2;

    buildf(l,mid,2*v+1);
    buildf(mid+1,r,2*v+2);

    Tf[v]=Tf[2*v+1]^Tf[2*v+2];
}

void builds(ll l, ll r, ll v)
{
    if (l==r)
    {
        if (l%2==1)
        {
            Ts[v]=0;
        }
        else
        {
            Ts[v]=a[l];
        }
        return;
    }

    ll mid=(l+r)/2;

    builds(l,mid,2*v+1);
    builds(mid+1,r,2*v+2);

    Ts[v]=Ts[2*v+1]^Ts[2*v+2];
}

void updf(ll tl, ll tr, ll v, ll pos, ll val)
{
    if (pos>tr||pos<tl) return;
    if (tl==tr&&tl==pos)
    {
        Tf[v]=val;
        return;
    }

    ll mid=(tl+tr)/2;
    updf(tl,mid,2*v+1,pos,val);
    updf(mid+1,tr,2*v+2,pos,val);

    Tf[v]=Tf[2*v+1]^Tf[2*v+2];
}

void upds(ll tl, ll tr, ll v, ll pos, ll val)
{
    if (pos>tr||pos<tl) return;
    if (tl==tr&&tl==pos)
    {
        Ts[v]=val;
        return;
    }

    ll mid=(tl+tr)/2;
    upds(tl,mid,2*v+1,pos,val);
    upds(mid+1,tr,2*v+2,pos,val);

    Ts[v]=Ts[2*v+1]^Ts[2*v+2];
}

ll fresf(ll tl, ll tr, ll v, ll l, ll r)
{
    if (tl>r||tr<l) return 0;
    if (tl>=l&&tr<=r) return Tf[v];

    ll mid=(tl+tr)/2;
    return fresf(tl,mid,2*v+1,l,r)^fresf(mid+1,tr,2*v+2,l,r);
}

ll fress(ll tl, ll tr, ll v, ll l, ll r)
{
    if (tl>r||tr<l) return 0;
    if (tl>=l&&tr<=r) return Ts[v];

    ll mid=(tl+tr)/2;
    return fress(tl,mid,2*v+1,l,r)^fress(mid+1,tr,2*v+2,l,r);
}

int main()
{
    speedup;

    cin >> n >> q;

    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
    }

    buildf(1,n,0);
    builds(1,n,0);

    while(q--)
    {
        cin >> t;
        if (t==1)
        {
            cin >> k >> l;
            if (k%2==0) upds(1,n,0,k,l);
            else updf(1,n,0,k,l);
        }
        else
        {
            cin >> l >> r;
            if ((r-l+1)%2==0) cout << 0 << endl;
            else
            {
                if (l%2==1) cout << fresf(1,n,0,l,r) << endl;
                else cout << fress(1,n,0,l,r) << endl;
            }
        }
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 360 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 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 360 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 340 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 3 ms 660 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 11184 KB Output is correct
2 Correct 126 ms 11172 KB Output is correct
3 Correct 130 ms 11212 KB Output is correct
4 Correct 119 ms 11208 KB Output is correct
5 Correct 106 ms 11216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 360 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 340 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 3 ms 660 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
15 Correct 126 ms 11184 KB Output is correct
16 Correct 126 ms 11172 KB Output is correct
17 Correct 130 ms 11212 KB Output is correct
18 Correct 119 ms 11208 KB Output is correct
19 Correct 106 ms 11216 KB Output is correct
20 Correct 120 ms 10756 KB Output is correct
21 Correct 119 ms 10692 KB Output is correct
22 Correct 119 ms 10632 KB Output is correct
23 Correct 109 ms 11220 KB Output is correct
24 Correct 115 ms 11184 KB Output is correct