-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathpoints_and_segments.py
More file actions
37 lines (29 loc) · 840 Bytes
/
points_and_segments.py
File metadata and controls
37 lines (29 loc) · 840 Bytes
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
# Uses python3
import sys
def fast_count_segments(starts, ends, points):
cnt = {}
segments_num = 0
listpoints = [(x, 'l') for x in starts]
listpoints += [(x, 'p') for x in points]
listpoints += [(x, 'r') for x in ends]
listpoints.sort()
for p in listpoints:
if p[1] == 'l':
segments_num += 1
elif p[1] == 'r':
segments_num -= 1
else:
cnt[p[0]] = segments_num
return [cnt[x] for x in points]
if __name__ == '__main__':
input = sys.stdin.read()
data = list(map(int, input.split()))
n = data[0]
m = data[1]
starts = data[2:2 * n + 2:2]
ends = data[3:2 * n + 2:2]
points = data[2 * n + 2:]
# use fast_count_segments
cnt = fast_count_segments(starts, ends, points)
for x in cnt:
print(x, end=' ')