Submission #725669

# Submission time Handle Problem Language Result Execution time Memory
725669 2023-04-17T20:44:07 Z MercubytheFirst XORanges (eJOI19_xoranges) C++14
100 / 100
537 ms 9936 KB
#include<iostream>
#include<vector>
using namespace std;


#define CDIV(a, b) (((a) + (b) - 1) / (b))
class ST{
    public:
    int n;
    vector<int>t, v;

    ST(int sz){
        n = sz;
        t.resize(4 * n);
        v.resize(n + 1);
    }

    void build(int node, int l, int r){
        if(l == r){
            t[node] = v[l];
            return;
        }
        int mid = (l + r)/2;
        build(node * 2, l, mid);
        build(node * 2 + 1, mid + 1, r);
        t[node] = t[node * 2] ^ t[node * 2 + 1];
    }

    int query(int node, int l, int r, int tl, int tr){
        if(l > r or r < tl or tr < l)return 0;
        if(tl <= l and r <= tr){
            return t[node];
        }
        int mid = (l + r)/2;
        int res = query(node * 2,l, mid, tl, tr) ^ query(node * 2 + 1, mid + 1, r, tl, tr);
        return res;
    }

    void update(int node, int l, int r, int idx, int val){
        if(l > r or r < idx or idx < l)return;
        if(l == r and idx == l){
            t[node] = val;
            return;
        }
        int mid = (l + r)/2;
        update(node * 2, l, mid, idx, val);
        update(node * 2 + 1, mid + 1, r, idx, val);
        t[node] = t[node * 2] ^ t[node * 2 + 1];
    }

};


int main(){
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    int n, q;
    cin >> n >> q;
    int esz = n/2, osz = CDIV(n,2);
    ST even(esz), odd(osz);
    for(int i = 1; i <= n; ++i){
        if(i % 2){
            cin >> odd.v[i/2 + 1];
        }
        else cin >> even.v[i/2];
    }
    even.build(1, 1,esz);
    odd.build(1, 1, osz);

    while(q--){
        int qt;
        cin >> qt;
        if(qt == 1){
            int idx, val;
            cin >> idx >> val;
            if(idx % 2){
                odd.update(1, 1, osz, idx/2 + 1, val);
            }
            else{
                even.update(1, 1, esz, idx/2, val);
            }
        }
        else{
            int l, r;
            cin >> l >> r;
            if((r - l + 1) % 2 == 0){
                cout << 0 << endl;
                continue;
            }
            if(l & 1){
                cout << odd.query(1, 1, osz, l/2 + 1, r/2 + 1) << endl;
            }
            else{
                cout << even.query(1, 1, esz, l/2, r/2) << endl;
            }
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 13 ms 468 KB Output is correct
12 Correct 12 ms 468 KB Output is correct
13 Correct 11 ms 520 KB Output is correct
14 Correct 11 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 525 ms 5408 KB Output is correct
2 Correct 486 ms 5388 KB Output is correct
3 Correct 537 ms 5412 KB Output is correct
4 Correct 488 ms 5368 KB Output is correct
5 Correct 494 ms 5392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 13 ms 468 KB Output is correct
12 Correct 12 ms 468 KB Output is correct
13 Correct 11 ms 520 KB Output is correct
14 Correct 11 ms 492 KB Output is correct
15 Correct 525 ms 5408 KB Output is correct
16 Correct 486 ms 5388 KB Output is correct
17 Correct 537 ms 5412 KB Output is correct
18 Correct 488 ms 5368 KB Output is correct
19 Correct 494 ms 5392 KB Output is correct
20 Correct 413 ms 9920 KB Output is correct
21 Correct 387 ms 9936 KB Output is correct
22 Correct 394 ms 9924 KB Output is correct
23 Correct 492 ms 9904 KB Output is correct
24 Correct 469 ms 9900 KB Output is correct