Submission #978035

# Submission time Handle Problem Language Result Execution time Memory
978035 2024-05-08T17:12:37 Z SeenSiravit XORanges (eJOI19_xoranges) C++14
75 / 100
129 ms 11348 KB
#include<bits/stdc++.h>
#define ll long long

using namespace std;

const int mxN = 2e5 + 5;

int n;
ll a[mxN][2];

ll seg[mxN * 2][2];

void build(int l , int r , int node , int t){
    if(l==r){
        seg[node][t] = a[l][t];
        return ;
    }

    int mid = (l + r) / 2;

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

    seg[node][t] = seg[node*2][t] ^ seg[node*2 + 1][t];
}

void update(int l , int r, int idx, int node , ll val , int t){
    if(l>idx || r<idx) return ;

    if(l == r){
        a[idx][t] = val;
        seg[node][t] = val;
        return ;
    }

    int mid = (l+r)/2;

    update(l,mid,idx,node*2,val,t);
    update(mid+1,r,idx,node*2 + 1 ,val,t);

    seg[node][t] = seg[node*2][t] ^ seg[node*2 + 1][t];
}

ll query(int l,int r,int curr_l,int curr_r,int node,int t){
    if(curr_l>r || curr_r<l) return 0;
    if(l<=curr_l && curr_r<=r) return seg[node][t];

    int mid = (curr_l + curr_r) / 2;
    
    return query(l,r,curr_l,mid,node*2,t) ^ query(l,r,mid+1,curr_r,node*2 + 1,t);
}

void display(){
    cout<< "\ndisplay\n";
    cout<< 1 << "\n";
    for(int i=1;i<=n;i++) cout<< a[i][1] << " ";
    cout<< "\n";
    for(int i=1;i<=2*n;i++) cout<< seg[i][1] << " ";

    cout<< "\n2\n";
    for(int i=1;i<=n;i++) cout<< a[i][0] << " ";
    cout<< "\n";
    for(int i=1;i<=2*n;i++) cout<< seg[i][0] << " ";
    cout<< "\n";
}

int main(){
    ios::sync_with_stdio(0),cin.tie(0);

    int q;

    cin>> n >> q;

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

    build(1 , n , 1 , 1);
    build(1 , n , 1 , 0);

    // cout<< "before \n";
    // display();

    while(q--){
        int cmd;
        cin>> cmd;

        if(cmd == 1){
            int idx;
            ll val;
            cin>> idx >> val;

            update(1,n,idx,1,val,idx&1);

            // display();
        }else{
            int l,r;
            cin>> l >> r;

            int len = r-l+1;

            // cout<< "ans = ";

            if(len%2 == 0){
                cout<< 0 << '\n';
                continue;
            }

            if(len & 1) cout<< query(l,r,1,n,1,l&1) << "\n";
            else cout<< query(l,r,1,n,1,l&1) << "\n";
        }
    }


    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 3 ms 6748 KB Output is correct
12 Correct 3 ms 6608 KB Output is correct
13 Correct 3 ms 6748 KB Output is correct
14 Correct 3 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 108 ms 11348 KB Output is correct
2 Correct 112 ms 11024 KB Output is correct
3 Correct 102 ms 10856 KB Output is correct
4 Correct 100 ms 10836 KB Output is correct
5 Correct 129 ms 10836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 3 ms 6748 KB Output is correct
12 Correct 3 ms 6608 KB Output is correct
13 Correct 3 ms 6748 KB Output is correct
14 Correct 3 ms 6748 KB Output is correct
15 Correct 108 ms 11348 KB Output is correct
16 Correct 112 ms 11024 KB Output is correct
17 Correct 102 ms 10856 KB Output is correct
18 Correct 100 ms 10836 KB Output is correct
19 Correct 129 ms 10836 KB Output is correct
20 Incorrect 111 ms 10324 KB Output isn't correct
21 Halted 0 ms 0 KB -