-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
executable file
·56 lines (44 loc) · 1.27 KB
/
main.cpp
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
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <bits/stdc++.h>
#define MAX 100001
using namespace std;
int N, M, a, b, c, input, last_ans = 0;
vector<int> tree[4 * MAX];
void update(int start, int end, int n, int index, int value) {
if (!(start <= index && index <= end))
return;
tree[n].push_back(value);
if (start != end) {
int mid = (start + end) / 2;
update(start, mid, 2 * n, index, value);
update(mid + 1, end, 2 * n + 1, index, value);
}
}
int query(int start, int end, int n, int value, int left, int right) {
if (left > end || right < start)
return 0;
if (left <= start && end <= right)
return tree[n].end() - upper_bound(tree[n].begin(), tree[n].end(), value);
else {
int mid = (start + end) / 2;
return query(start, mid, 2 * n, value, left, right) +
query(mid + 1, end, 2 * n + 1, value, left, right);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
for (int i = 0; i < N; i++) {
cin >> input;
update(0, N - 1, 1, i, input);
}
for (int i = 1; i < 4 * N; i++)
sort(tree[i].begin(), tree[i].end());
cin >> M;
for (int i = 0; i < M; i++) {
cin >> a >> b >> c;
last_ans = query(0, N - 1, 1, (c ^ last_ans), (a ^ last_ans) - 1,
(b ^ last_ans) - 1);
cout << last_ans << "\n";
}
}