DatabricksOA #20
Lamps Illumination
Estimated MediumJudge-ready
Topics (AI-labelled)Prefix & RangesBinary Search
Each lamp covers a closed interval [left,right] on the integer number line. Given several query points, output how many lamps illuminate each point.
Standard input/output and this site's supplementary ranges follow this problem's description.
Input
The first line contains m q (0≤m≤50000, 1≤q≤50000), followed by m lines giving left right (−10⁹≤left≤right≤10⁹); the last line gives the q query points (−10⁹≤point≤10⁹). The length limits are site supplements.
Output
One line with q integers giving the number of covering lamps for each query point in input order, separated by spaces.
Example 1
Input:
3 7
1 7
3 5
4 6
1 3 4 5 6 7 8
Output:
1 2 3 3 2 1 0
Example 2
Input:
0 3
-1 0 1
Output:
0 0 0
Example 3
Input:
3 5
-2 2
-2 -2
2 2
-3 -2 0 2 3
Output:
0 2 1 2 0
Editorial
Loading solution…