답안 #637334

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
637334 2022-09-01T11:49:42 Z ulianamalanyak XORanges (eJOI19_xoranges) C++14
0 / 100
152 ms 11224 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 build(ll l, ll r, ll v)
{
    if (l==r)
    {
        Tf[v]=a[l];
        Ts[v]=0;
        return;
    }

    ll mid=(l+r)/2;

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

    ll tmp=(mid-l+1);

    Tf[v]=Tf[2*v+1];
    Ts[v]=Ts[2*v+1];

    if (tmp%2==0)
    {
        Tf[v]^=Tf[2*v+2];
        Ts[v]^=Ts[2*v+2];
    }
    else
    {
        Tf[v]^=Ts[2*v+2];
        Ts[v]^=Tf[2*v+2];
    }
    return;
}

pll fres(ll tl, ll tr, ll  v, ll l, ll r)
{
    //cout << "!!" << endl;
    if (tl>r||tr<l) return {0,0};
    if (tl>=l&&tr<=r) return {Tf[v],Ts[v]};

    ll mid=(tl+tr)/2;
    pll t1=fres(tl,mid,2*v+1,l,r);
    pll t2=fres(mid+1,tr,2*v+2,l,r);

    ll tmp=max((mid-l+1),0LL);

    //cout << "! " << tl << " " << tr << " ";
    if (tmp%2==0)
    {
        //cout << (t1.fi^t2.fi) << " " << (t1.se^t2.se) << endl;
        return {t1.fi^t2.fi,t1.se^t2.se};
    }
    else
    {
        //cout << (t1.fi^t2.se) << " " << (t1.se^t2.fi) << endl;
        return {t1.fi^t2.se,t1.se^t2.fi};
    }
}

void upd(ll l, ll r, ll v, ll pos, ll val)
{
    //cout << "!" << endl;
    if (pos<l||pos>r) return;
    if (l==r&&l==pos)
    {
        Tf[v]=val;
        Ts[v]=0;
        return;
    }

    ll mid=(l+r)/2;
    upd(l,mid,2*v+1,pos,val);
    upd(mid+1,r,2*v+2,pos,val);

    ll tmp=max((mid-l+1),0LL);

    //cout << "! " << l << " " << r << endl;
    //cout << Tf[v] << " " << Ts[v] << endl;

    Tf[v]=Tf[2*v+1];
    Ts[v]=Ts[2*v+1];

    if (tmp%2==0)
    {
        Tf[v]^=Tf[2*v+2];
        Ts[v]^=Ts[2*v+2];
    }
    else
    {
        Tf[v]^=Ts[2*v+2];
        Ts[v]^=Tf[2*v+2];
    }
    //cout << Tf[v] << " " << Ts[v] << endl;
    return;
}

int main()
{
    speedup;

    cin >> n >> q;

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

    build(1,n,0);

    while(q--)
    {
        cin >> t;
        if (t==1)
        {
            cin >> k >> l;
            upd(1,n,0,k,l);
        }
        else
        {
            cin >> l >> r;
            if ((r-l+1)%2==0) cout << 0 << endl;
            else cout << fres(1,n,0,l,r).fi << endl;
        }
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 152 ms 11224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -