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

Code

#include <bits/stdc++.h>

using namespace std;

//Definitions for quicker writing
#define REP(i,c,d) for (int i = c; i < d; i++)

//Typedefs for quicker writing
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;


int main() {
	//IO optimization
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	//Input definition
	int n;
	int q;

	cin >> n >> q;

	//Initialize segment tree
	ll seg[2*n];
	seg[0] = -1;

	REP(i,0,n){
		cin >> seg[i+n];
	}

	for(int i=n-1;i>0;i--){
		seg[i] = seg[2*i] ^ seg[(2*i)+1];
	}
	
	//REP(i,0,2*n){
	//	cout << seg[i] << "\n";
	//}

	ll a;
	ll b;

	ll res[q];

	REP(i,0,q){
		cin >> a;
		cin >> b;

		a += n-1;
		b += n-1;
		ll s = 0;
		while(a <= b){
			if(a%2 == 1){
				s = s^seg[a++];
			}	
			if(b%2 == 0){
				s = s^seg[b--];
			}
			a /= 2;
			b /= 2;
		}
		res[i] = s;
	}
	

	//Write out
	REP(i,0,q){
		cout << res[i] << "\n";
	}	

	//Return
	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