Submission #675717

# Submission time Handle Problem Language Result Execution time Memory
675717 2022-12-27T18:51:16 Z a_aguilo XORanges (eJOI19_xoranges) C++14
100 / 100
598 ms 9720 KB
#include<bits/stdc++.h>

using namespace std;

vector<int> segTreeOdd, segTreeEven, Odds, Evens;
int n, q;

void setUpSegTree(int node, int left, int right, vector<int>& refVector, vector<int>& SegTree){
    if(left == right) {
        SegTree[node] = refVector[left];
        return;
    }
    if(left > right) return;
    int mid = left + (right - left)/2;
    setUpSegTree(2*node, left, mid, refVector, SegTree);
    setUpSegTree(2*node+1, mid+1, right, refVector, SegTree);
    SegTree[node] = SegTree[2*node]^SegTree[2*node+1];
}

void update(int node, int left, int right, int position, int newVal, vector<int>& SegTree){
    if(right < position || left > position) return;
    if(right < left) return;
    //cout << "Node " << node << " leftBound " << left << " rightBound " << right << endl;
    if(right == left){
        SegTree[node] = newVal;
        return;
    }
    int mid = left + (right - left)/2;
    update(2*node, left, mid, position, newVal, SegTree);
    update(2*node+1, mid+1, right, position, newVal, SegTree);
    SegTree[node] = SegTree[2*node]^SegTree[2*node+1];
    //cout << "Node " << node << " leftBound " << left << " rightBound " << right << " segtree val " << SegTree[node] <<  endl;
}

int getValue(int node, int left, int right, int leftBound, int rightBound, vector<int>& SegTree){
    //cout << node << " " << left << " " << right << " " << leftBound << " " << rightBound << endl;
    if(left > rightBound || right < leftBound) return 0;
    if(left > right) return 0;
    if(leftBound <= left && rightBound >= right) return SegTree[node];
    int mid = left + (right - left)/2;
    return (getValue(2*node, left, mid, leftBound, rightBound, SegTree)^getValue(2*node+1, mid+1, right, leftBound, rightBound, SegTree));
}
int main(){
    cin >> n >> q;
    int ask, l, r, pos, newVal, concretePos;
    vector<int> indices(n);
    for(int i = 0; i < n; ++i){
        cin >> indices[i];
        if(i%2){//índice IMPAR
            Odds.push_back(indices[i]);
        }else{
            Evens.push_back(indices[i]);
        }
    }
    segTreeOdd = vector<int>(4*Odds.size());
    setUpSegTree(1, 0, Odds.size()-1, Odds, segTreeOdd);
    segTreeEven = vector<int>(4*Evens.size());
    setUpSegTree(1, 0, Evens.size()-1, Evens, segTreeEven);
    while(q--){
        cin >> ask;
        if(ask == 1){
            cin >> pos >> newVal;
            pos--;
            if(pos%2){
                update(1, 0, Odds.size()-1, pos/2, newVal, segTreeOdd);
            }else{
                update(1, 0, Evens.size()-1, pos/2, newVal, segTreeEven);
            }
        }else{
            cin >> l >> r;l--; r--;
            if((l-r+1)%2){
                if(l%2== 0){
                    cout << getValue(1, 0, Evens.size()-1, l/2, r/2, segTreeEven)<< endl;
                }
                else{
                    cout << getValue(1, 0, Odds.size()-1, l/2, r/2, segTreeOdd) << endl;
                }
            }else{
                cout << 0 << endl;
            }
        }
    }
    return 0;
}

Compilation message

xoranges.cpp: In function 'int main()':
xoranges.cpp:45:33: warning: unused variable 'concretePos' [-Wunused-variable]
   45 |     int ask, l, r, pos, newVal, concretePos;
      |                                 ^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 288 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 2 ms 256 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 2 ms 312 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 300 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 3 ms 212 KB Output is correct
9 Correct 2 ms 312 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 12 ms 572 KB Output is correct
12 Correct 9 ms 468 KB Output is correct
13 Correct 14 ms 560 KB Output is correct
14 Correct 18 ms 560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 598 ms 9720 KB Output is correct
2 Correct 525 ms 7160 KB Output is correct
3 Correct 544 ms 7100 KB Output is correct
4 Correct 546 ms 7124 KB Output is correct
5 Correct 511 ms 7164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 3 ms 212 KB Output is correct
9 Correct 2 ms 312 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 12 ms 572 KB Output is correct
12 Correct 9 ms 468 KB Output is correct
13 Correct 14 ms 560 KB Output is correct
14 Correct 18 ms 560 KB Output is correct
15 Correct 598 ms 9720 KB Output is correct
16 Correct 525 ms 7160 KB Output is correct
17 Correct 544 ms 7100 KB Output is correct
18 Correct 546 ms 7124 KB Output is correct
19 Correct 511 ms 7164 KB Output is correct
20 Correct 394 ms 6548 KB Output is correct
21 Correct 428 ms 6536 KB Output is correct
22 Correct 453 ms 6580 KB Output is correct
23 Correct 543 ms 7076 KB Output is correct
24 Correct 490 ms 7108 KB Output is correct