CSES Solutions
#1650Range Queries

Range Xor Queries

View on CSES

Solution

1650-Range_Xor_Queries.cpp
1#include<bits/stdc++.h>
2using namespace std;
3#define int long long
4signed main(){
5  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
6  int n,q; cin>>n>>q;
7  int a[n+1]; for(int i=1;i<=n;++i){
8    cin>>a[i];
9  }
10  int pxor[n+1]; pxor[0]=0;
11  for(int i=1;i<=n;++i) pxor[i]=pxor[i-1]^a[i];
12  while(q--){
13    int a,b; cin>>a>>b;
14    cout<<(pxor[b]^pxor[a-1])<<'\n';
15  }
16  return 0;
17}

Editorial not yet generated for this problem. Run the editorial generation script to add hints and detailed explanations.