Submission #911088

# Submission time Handle Problem Language Result Execution time Memory
911088 2024-01-18T12:39:37 Z speedcode XORanges (eJOI19_xoranges) C++17
100 / 100
128 ms 8028 KB
#include <bits/stdc++.h>
using namespace std;

int biggestPowOf2(int i){
    int res = 1;
    while(i % 2 == 0){
        res *= 2;
        i /= 2;
    }
    return res;
}

void xorToArray(long long* arr, int index, long long value, int arrLength){
    while(index < arrLength){
        arr[index] ^= value;
        index += biggestPowOf2(index);
    }
}

int ArraySum(long long* arr, int index){
    if(index == 0) return 0;
    return arr[index] ^ ArraySum(arr, index - biggestPowOf2(index));
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,q;
    cin >> n >> q;
    long long oddValues[(n+1)/2 + 1];
    int oddLength = (n+1)/2 + 1;
    long long evenValues[n/2 + 1];
    int evenLength = n/2 + 1;
    fill(oddValues,oddValues + oddLength, 0);
    fill(evenValues,evenValues + evenLength, 0);
    for(int i = 1; i <= n; i++){
        long long r;
        cin >> r;
        if(i%2 == 0){
            xorToArray(evenValues, i/2, r, evenLength);
        } else {
            xorToArray(oddValues, i/2 + 1, r, oddLength);
        }
    }
    for(int i = 0; i < q; i++){
        short int t;
        cin >> t;
        if(t==2){
            int l,u;
            cin >> l >> u;
            if((l-u)%2 != 0){
                cout << "0\n";
            } else if(l%2 == 0){
                cout << (ArraySum(evenValues, u/2) ^ ArraySum(evenValues, l/2 - 1)) << '\n';
            } else {
                cout << (ArraySum(oddValues, u/2 + 1) ^ ArraySum(oddValues, l/2)) << '\n';
            }

        } else {
            int I;
            long long val;
            cin >> I;
            cin >> val;
            if(I%2 == 0){
                xorToArray(evenValues, I/2, (ArraySum(evenValues, I/2) ^ ArraySum(evenValues, I/2 - 1) ^ val), evenLength);
            } else {
                xorToArray(oddValues, I/2 + 1, (ArraySum(oddValues, I/2 + 1) ^ ArraySum(oddValues, I/2) ^ val), oddLength);
            }
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 3 ms 856 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 8020 KB Output is correct
2 Correct 104 ms 8028 KB Output is correct
3 Correct 107 ms 7868 KB Output is correct
4 Correct 113 ms 7624 KB Output is correct
5 Correct 97 ms 7500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 3 ms 856 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 103 ms 8020 KB Output is correct
16 Correct 104 ms 8028 KB Output is correct
17 Correct 107 ms 7868 KB Output is correct
18 Correct 113 ms 7624 KB Output is correct
19 Correct 97 ms 7500 KB Output is correct
20 Correct 128 ms 7588 KB Output is correct
21 Correct 125 ms 7740 KB Output is correct
22 Correct 125 ms 7540 KB Output is correct
23 Correct 94 ms 7508 KB Output is correct
24 Correct 98 ms 7600 KB Output is correct