Points and Line Segments
Given N
segments on a number line and M
points on the same line, your task is to determine how many of these segments each point belongs to.
A point x
is considered to belong to a segment defined by endpoints a
and b
if it satisfies the following condition:
min(a, b) ≤ x
≤ max(a, b).
Input
The first line contains two integers, N
and M
, representing the number of segments and the number of points, respectively (1 ≤ N, M ≤ 10^5
). The next N
lines each contain two integers, a[i]
and b[i]
, which are the coordinates of the endpoints of the i
-th segment. The final line contains M
integers, which are the coordinates of the points. All numbers in the input are within the range of -10^9
to 10^9
.
Output
Print M
integers, where each integer corresponds to the number of segments that contain the respective point.