-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabc248_d.cpp
More file actions
53 lines (42 loc) · 1.07 KB
/
abc248_d.cpp
File metadata and controls
53 lines (42 loc) · 1.07 KB
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 2e5;
unordered_map<int, int> tree[MAX*4];
void update(int s, int e, int node, int index, int f) {
if (s > index || e < index) return;
tree[node][f]++;
if (s == e) return;
int m = (s+e)/2;
update(s, m, node*2, index, f);
update(m+1, e, node*2+1, index, f);
}
int query(int s, int e, int node, int l, int r, int c) {
if (s > r || e < l) return 0;
if (l <= s && r >= e) {
if (tree[node].count(c)) return tree[node][c];
return 0;
}
int m = (s+e)/2;
return query(s, m, node*2, l, r, c) + query(m+1, e, node*2+1, l, r, c);
}
void solve(){
int N; cin >> N;
for (int i = 1; i <= N; i++) {
int a; cin >> a;
update(1, N, 1, i, a);
}
int M; cin >> M;
while (M--) {
int l, r, c;
cin >> l >> r >> c;
cout << query(1, N, 1, l, r, c);
cout << '\n';
}
}
int main()
{
cin.tie(0)->sync_with_stdio(false);
solve();
return 0;
}