Submission #999779

# Submission time Handle Problem Language Result Execution time Memory
999779 2024-06-16T06:48:02 Z hacizadal XORanges (eJOI19_xoranges) C++17
100 / 100
93 ms 15316 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;
                }
            }
        }
    }
}
# Verdict Execution time Memory 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 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 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory 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
6 Correct 1 ms 4440 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 4440 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 2 ms 6744 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 15160 KB Output is correct
2 Correct 81 ms 15316 KB Output is correct
3 Correct 80 ms 15016 KB Output is correct
4 Correct 73 ms 14992 KB Output is correct
5 Correct 74 ms 15188 KB Output is correct
# Verdict Execution time Memory 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
6 Correct 1 ms 4440 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 4440 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 2 ms 6744 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 82 ms 15160 KB Output is correct
16 Correct 81 ms 15316 KB Output is correct
17 Correct 80 ms 15016 KB Output is correct
18 Correct 73 ms 14992 KB Output is correct
19 Correct 74 ms 15188 KB Output is correct
20 Correct 88 ms 14464 KB Output is correct
21 Correct 88 ms 14416 KB Output is correct
22 Correct 93 ms 14416 KB Output is correct
23 Correct 79 ms 15136 KB Output is correct
24 Correct 77 ms 14932 KB Output is correct