-
Notifications
You must be signed in to change notification settings - Fork 0
/
Adarain.cpp
44 lines (44 loc) · 861 Bytes
/
Adarain.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
// Ivan Carvalho
// Solution to https://www.spoj.com/problems/ADARAIN/
#include <cstdio>
#define LSOne(S) (S & -S)
const int MAXN = 1e6 + 10;
int n, m, l, bit[MAXN];
inline void updateplus(int idx) {
while (idx < MAXN) {
bit[idx]++;
idx += LSOne(idx);
}
}
inline void updateless(int idx) {
while (idx < MAXN) {
bit[idx]--;
idx += LSOne(idx);
}
}
inline int query(int idx) {
int ans = 0;
while (idx > 0) {
ans += bit[idx];
idx -= LSOne(idx);
}
return ans;
}
int main() {
scanf("%d %d %d", &n, &m, &l);
while (n--) {
int a, b;
scanf("%d %d", &a, &b);
a++;
b++;
updateplus(a);
updateless(b + 1);
}
while (m--) {
int a;
scanf("%d", &a);
a++;
printf("%d\n", query(a));
}
return 0;
}