답안 #999780

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
999780 2024-06-16T06:48:14 Z vjudge1 XORanges (eJOI19_xoranges) C++17
100 / 100
95 ms 15188 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*4], t1[sz*4];
 
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];
}
 
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);
    }
    t1[v] = t1[v*2] ^ t1[v*2+1];
}
 
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 Correct 1 ms 4440 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 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 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 3 ms 6748 KB Output is correct
13 Correct 3 ms 6716 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 15188 KB Output is correct
2 Correct 81 ms 15184 KB Output is correct
3 Correct 79 ms 15064 KB Output is correct
4 Correct 89 ms 15040 KB Output is correct
5 Correct 95 ms 15184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 3 ms 6748 KB Output is correct
13 Correct 3 ms 6716 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 80 ms 15188 KB Output is correct
16 Correct 81 ms 15184 KB Output is correct
17 Correct 79 ms 15064 KB Output is correct
18 Correct 89 ms 15040 KB Output is correct
19 Correct 95 ms 15184 KB Output is correct
20 Correct 78 ms 14420 KB Output is correct
21 Correct 78 ms 14540 KB Output is correct
22 Correct 76 ms 14612 KB Output is correct
23 Correct 81 ms 15164 KB Output is correct
24 Correct 76 ms 14936 KB Output is correct