cswork / OA打开练习工作台

ZipRecruiterOA #11

Lamps and Control Points

估计中等可在线判题

考点(AI 标注)前缀和区间二分查找

There are several lamps on a number line, each lighting a segment: lamp i covers the segment from lamps[i][0] to lamps[i][1] (inclusive). You are also given an array of control points points. For each control point points[j], find how many lamps light it, that is, the number of lamps for which points[j] lies within [lamps[i][0],lamps[i][1]]. Output the answers in control-point order.

输入格式

The first line contains two integers n and m; then n lines follow, each with two integers l and r describing a lamp; the last line contains m integers points. 1≤n,m≤100000, −10^9≤l≤r≤10^9, −10^9≤points[j]≤10^9.

输出格式

Output one line of m integers; the j-th is the number of lamps lighting points[j].

样例 1

输入:

3 6
1 7
5 11
7 9
7 1 5 10 9 15

输出:

3 1 2 1 2 0

样例 2

输入:

1 4
2 4
1 2 4 5

输出:

0 1 1 0

样例 3

输入:

2 3
0 3
0 3
3 0 -1

输出:

2 2 0

样例说明

Example 1: lamps [1,7], [5,11], [7,9]. Point 7 is lit by three lamps, point 1 by 1, point 5 by 2, point 10 by 1, point 9 by 2, and point 15 by none, so output 3 1 2 1 2 0. Example 2: endpoints 2 and 4 are both lit, while 1 and 5 are not. Example 3: both identical lamps [0,3] are counted.