-
Notifications
You must be signed in to change notification settings - Fork 9
/
ADARAIN - Ada and Rain.cpp
64 lines (64 loc) · 1.43 KB
/
ADARAIN - Ada and Rain.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
58
59
60
61
62
63
64
include<bits/stdc++.h>
#define mx 1000006
int tree[mx*4],lazy[mx*4];
void update(int pos, int b, int e, int i, int j, int val)
{
int m = (b+e)/2;
int l = pos*2 + 1;
int r = l+1;
if(lazy[pos]!=0){
tree[pos] = tree[pos] + (e-b+1)*lazy[pos];
if(b!=e){
lazy[l]+=lazy[pos];
lazy[r]+=lazy[pos];
}
lazy[pos] = 0;
}
if(b>e || b>j ||e<i) return;
if(b>=i && e<=j){
tree[pos] = tree[pos] + (e-b+1)*val;
if(b!=e){
lazy[l]+=val;
lazy[r]+=val;
}
return;
}
update(l,b,m,i,j,val);
update(r,m+1,e,i,j,val);
tree[pos] = tree[l]+tree[r];
}
int query(int pos, int b, int e, int i, int j)
{
int m = (b+e)/2;
int l = pos*2 + 1;
int r = l+1;
if(lazy[pos]!=0){
tree[pos] = tree[pos] + (e-b+1)*lazy[pos];
if(b!=e){
lazy[l]+=lazy[pos];
lazy[r]+=lazy[pos];
}
lazy[pos] = 0;
}
if(b>e || b>j ||e<i) return 0;
if(b>=i && e<=j){
return tree[pos];
}
int r1 = query(l,b,m,i,j);
int r2 = query(r,m+1,e,i,j);
return (r1+r2);
}
int main()
{
int n,m,w,a,b;
scanf("%d%d%d",&n,&m,&w);
while(n--){
scanf("%d%d",&a,&b);
update(0,0,w-1,a,b,1);
}
while(m--){
scanf("%d",&a);
printf("%d\n",query(0,0,w-1,a,a));
}
return 0;
}