Submission #769591

# Submission time Handle Problem Language Result Execution time Memory
769591 2023-06-29T20:18:40 Z GordonRemzi007 XORanges (eJOI19_xoranges) C++17
100 / 100
425 ms 7896 KB
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

class SegmentTree {
    int n, i = 0;
    vector<int> seggy;
public:
    SegmentTree(int size):n(size) {
        seggy = vector<int>(2*n);
    }
    void push(int x) {
        seggy[n+i] = x;
        i++;
    }
    void build() {
        for(int i = n-1; i > 0; i--) seggy[i] = seggy[2*i]^seggy[2*i+1];
    }
    void update(int x, int y) {
        x+=n;
        seggy[x] = y;
        while(x > 1) {
            x/=2;
            seggy[x] = seggy[2*x]^seggy[2*x+1];
        }
    }
    int query(int x, int y) {
        int res = 0;
        for (x+=n, y+=n+1; x<y; x/=2, y/=2) {
            if (x&1) res ^= seggy[x++];
            if (y&1) res ^= seggy[--y];
        }
        return res;
    }
};

int main() {
    int n, q, t, x, y;
    cin >> n >> q;
    SegmentTree S1(n/2), S2((n+1)/2);
    for(int i = 0; i < n; i++) {
        cin >> x;
        if(i%2) S1.push(x);
        else S2.push(x);
    }
    S1.build();
    S2.build();
    while(q--) {
        cin >> t >> x >> y;
        x--;
        if(t == 1) {
            if(x%2) S1.update((x-1)/2, y);
            else S2.update(x/2, y);
        } else {
            y--;
            if((y-x+1)%2 == 0) cout << "0\n";
            else {
                if(x%2) cout << S1.query((x-1)/2, (y-1)/2) << "\n";
                else cout << S2.query(x/2, y/2) << "\n";
            }
        }
    }
}
# 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 212 KB Output is correct
5 Correct 1 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 304 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 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 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 9 ms 468 KB Output is correct
12 Correct 7 ms 468 KB Output is correct
13 Correct 9 ms 436 KB Output is correct
14 Correct 9 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 400 ms 7896 KB Output is correct
2 Correct 393 ms 7844 KB Output is correct
3 Correct 384 ms 7884 KB Output is correct
4 Correct 388 ms 7564 KB Output is correct
5 Correct 400 ms 7488 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 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 9 ms 468 KB Output is correct
12 Correct 7 ms 468 KB Output is correct
13 Correct 9 ms 436 KB Output is correct
14 Correct 9 ms 468 KB Output is correct
15 Correct 400 ms 7896 KB Output is correct
16 Correct 393 ms 7844 KB Output is correct
17 Correct 384 ms 7884 KB Output is correct
18 Correct 388 ms 7564 KB Output is correct
19 Correct 400 ms 7488 KB Output is correct
20 Correct 290 ms 7628 KB Output is correct
21 Correct 285 ms 7540 KB Output is correct
22 Correct 296 ms 7716 KB Output is correct
23 Correct 425 ms 7492 KB Output is correct
24 Correct 372 ms 7632 KB Output is correct