-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRangeXORQueries.cpp
More file actions
43 lines (36 loc) · 918 Bytes
/
Copy pathRangeXORQueries.cpp
File metadata and controls
43 lines (36 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, q;
const int Sz = 2e5 + 2;
int st[Sz * 4 + 1];
void Build(int id, int l, int r){
if(l == r){
int x;
cin >> x;
st[id] = x;
return;
}
int mid = (l + r) >> 1;
Build(id << 1, l, mid);
Build(id << 1 | 1, mid + 1, r);
st[id] = st[id << 1] ^ st[id << 1 | 1];
}
int get(int id, int l, int r, int u, int v){
if(u <= l && r <= v) return st[id];
int mid = (l + r) >> 1;
if(mid < u) return get(id << 1 | 1, mid + 1, r, u, v);
if(v < mid + 1) return get(id << 1, l, mid, u, v);
return get(id << 1, l, mid, u, v) ^ get(id << 1 | 1, mid + 1, r, u, v);
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> q;
Build(1, 1, n);
while(q--){
int l, r;
cin >> l >> r;
cout << get(1, 1, n, l, r) << "\n";
}
}