-
Notifications
You must be signed in to change notification settings - Fork 0
/
dots_and_lines.py
51 lines (47 loc) · 1.36 KB
/
dots_and_lines.py
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
def quick_sort(x):
if not x: return []
if len(x) == 1:
return x
l, c, r = [], [], []
x[0], x[len(x) // 2] = x[len(x) // 2], x[0]
c.append(x[0])
for i in range(1, len(x)):
if x[i] < x[0]:
l.append(x[i])
elif x[i] == x[0]:
c.append(x[i])
elif x[i] > x[0]:
r.append(x[i])
return quick_sort(l) + c + quick_sort(r)
def search_l(x, i, l, r):
if l < r:
m = (r + l) // 2
if x[m] <= i:
return search_l(x, i, m + 1, r)
else:
return search_l(x, i, l, m - 1) if m != l else search_l(x, i, l, m)
return l+1 if x[l] <= i else l
def search_r(x, i, l, r):
if l < r:
m = (r + l) // 2
if x[m] < i:
return search_r(x, i, m + 1, r)
else:
return search_r(x, i, l, m - 1) if m != l else search_r(x, i, l, m)
return l-1 if x[l] >= i else l
def main():
l, r = [], []
n, m = [int(i) for i in input().split()]
for i in range(n):
x, y = [int(j) for j in input().split()]
l.append(x)
r.append(y)
dots = [int(i) for i in input().split()]
l = quick_sort(l)
r = quick_sort(r)
for dot in dots:
x = search_l(l, dot, 0, len(l) - 1)
y = search_r(r, dot, 0, len(l) - 1)
print(x - y - 1, end=' ')
if __name__ == '__main__':
main()