답안 #999765

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
999765 2024-06-16T06:33:56 Z hacizadal XORanges (eJOI19_xoranges) C++17
18 / 100
86 ms 7760 KB
/* :) */
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define pll pair<ll, ll>
const int sz = 2e5+5;
ll a[sz], b[sz], t[sz], t1[sz];

void build(ll v, ll l, ll r)
{
    if (l == r){
        t[v] = a[l];
        t1[v] = b[l];
        return;
    }
    ll m = (l + r)/2;
    build(v*2, l, m);
    build(v*2+1, m+1, r);
    t[v] = t[v*2] ^ t[v*2+1];
    t1[v] = t1[v*2] ^ t1[v*2+1];
}

void update(ll v, ll l, ll r, ll ind, ll val)
{
    if (l == r){
        t[v] = val;
        return;
    }
    ll m = (l + r)/2;
    if (ind <= m){
        update(v*2, l, m, ind, val);
    }
    else {
        update(v*2+1, m+1, r, ind, val);
    }
    t[v] = t[v*2] ^ t[v*2+1];
    t1[v] = t1[v*2] ^ t1[v*2+1];
}

void update1(ll v, ll l, ll r, ll ind, ll val)
{
    if (l == r){
        t1[v] = val;
        return;
    }
    ll m = (l + r)/2;
    if (ind <= m){
        update1(v*2, l, m, ind, val);
    }
    else {
        update1(v*2+1, m+1, r, ind, val);
    }
}

ll ans(ll v, ll l, ll r, ll tl, ll tr)
{
    if (l>tr or r<tl) return 0;
    if (tl<=l and r<=tr) return t[v];
    ll m = (l + r)/2;
    return ans(v*2, l, m, tl, tr) ^ ans(v*2+1, m+1, r, tl, tr);
}

ll ans1(ll v, ll l, ll r, ll tl, ll tr)
{
    if (l>tr or r<tl) return 0;
    if (tl<=l and r<=tr) return t1[v];
    ll m = (l + r)/2;
    return ans1(v*2, l, m, tl, tr) ^ ans1(v*2+1, m+1, r, tl, tr);
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n, q, k, x;
    cin>>n>>q;
    for (ll i = 1; i<=n; i++){
        cin>>x;
        if (i%2==0) b[i] = x;
        else        a[i] = x;
    }
    build(1, 1, n);
    while (q--){
        cin>>k;
        if (k == 1){
            ll i, j;
            cin>>i>>j;
            if (i%2==0){
                update1(1, 1, n, i, j);
            }
            else {
                update(1, 1, n, i, j);
            }
        }
        else {
            ll l, r;
            cin>>l>>r;
            if ((r-l+1)%2==0){
                cout<<0<<endl;
            }
            else{
                if (l%2==0){
                    cout<<ans1(1, 1, n, l, r)<<endl;
                }
                else {
                    cout<<ans(1, 1, n, l, r)<<endl;
                }
            }
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4576 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 86 ms 7760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -