CSES - Aalto Competitive Programming 2024 - wk4 - Mon - Results
Submission details
Task:Xor sum
Sender:laluj
Submission time:2024-09-23 16:39:15 +0300
Language:C++ (C++17)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.51 sdetails

Compiler report

input/code.cpp: In function 'std::vector<int> prefix_sum(std::vector<int>&)':
input/code.cpp:10:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for (int i = 1; i < arr.size(); ++i) {
      |                     ~~^~~~~~~~~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:22:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |     for (size_t i = 0; i < n; i++) {
      |                        ~~^~~
input/code.cpp:29:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |     for (size_t i = 0; i < q; i++) {
      |                        ~~^~~
input/code.cpp:35:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-co...

Code

#include <bits/stdc++.h>

using namespace std;

#define debug(x) cerr << #x << ': ' << x << endl;

vector<int> prefix_sum(vector<int>& arr) {
    vector<int> psum(arr.size());
    psum[0] = arr[0];
    for (int i = 1; i < arr.size(); ++i) {
        psum[i] = psum[i - 1] ^ arr[i];
    }
    return psum;
}

int main() {

    int n,q;
    cin >> n >> q;

    vector<int> x (n);
    for (size_t i = 0; i < n; i++) {
        cin >> x[i];
    }

    vector<int> psum = prefix_sum(x);

    int a[q],b[q];
    for (size_t i = 0; i < q; i++) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }

    for (size_t i = 0; i < q; i++) {
        int res = psum[a[i]-1] ^ psum[b[i]];
        cout << res << endl;
    }

    return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
8 36
7 6 4 6 2 9 4 8
1 1
1 2
1 3
...

correct output
7
1
5
3
1
...

user output
7
1
5
3
1
...

Test 2

Verdict: ACCEPTED

input
200000 200000
921726510 307633388 992247073 ...

correct output
834756431
130379787
403037296
308618218
784778243
...

user output
834756431
130379787
403037296
308618218
784778243
...
Truncated