Points and segments
Time: 1 s · Memory: 256 MB
- Sorting
Statement
You are given segments and points on a number line. For every point find how many segments contain it. Point belongs to the segment with ends and if .
Input format
The first line contains and (). The next lines contain and — the ends of a segment (in any order). The last line contains integers — the points. All numbers are at most in absolute value.
Output format
A single line with numbers — one for every point, in input order.
Examples
Input
3 2 0 5 -3 2 7 10 1 6
Output
2 0
Input
1 3 -10 10 -100 100 0
Output
0 0 1
Note
Checking every pair is — operations. The number of segments containing is (segments with left end ) − (segments with right end ). Sort the left and right ends separately and find both counts for every point with binary search: .
The ends may be given in reverse order () — order them first. A point at an end of a segment belongs to it.
Source: acmp.ru, problem 396.
