-
Notifications
You must be signed in to change notification settings - Fork 0
/
13537.cpp
57 lines (46 loc) · 1.18 KB
/
13537.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
57
#include<iostream>
#include<algorithm>
#include<vector>
#define N 100005
using namespace std;
int n, m, a1, a2, a3, mi;
vector<int> st[N*3];
void make_tree(int left, int right, int index, int goal)
{
if(goal<left || right<goal) return;
mi = max(mi, index);
st[index].push_back(a1);
if(left==right) return;
int mid=(left+right)/2;
make_tree(left, mid, index*2, goal);
make_tree(mid+1, right, index*2+1, goal);
}
int get_tree(int left, int right, int index)
{
if(right<a1 || a2<left) return 0;
if(a1<=left && right<=a2) return st[index].end() - upper_bound(st[index].begin(), st[index].end(), a3);
int mid=(left+right)/2;
return get_tree(left, mid, index*2) + get_tree(mid+1, right, index*2+1);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int i, a;
cin >> n;
for(i=1; i<=n; i++){
cin >> a1;
make_tree(1, n, 1, i);
}
for(i=1; i<=mi; i++){
sort(st[i].begin(), st[i].end());
}
cin >> m;
for(i=1; i<=m; i++){
cin >> a1 >> a2 >> a3;
printf("%d\n", get_tree(1, n, 1));
}
return 0;
}