Problems > How Many Intervals Cover X

How Many Intervals Cover X

Difficulty: 1400 3500 ms 128 MB

intervals prefix-sums

N intervals [L, R] over coordinates 1..105 are given, then Q point queries: how many intervals contain the point X?

Input: the first line has N and Q; the next N lines have the intervals; the next Q lines each have one X.

Output: Q lines with the coverage counts.

Constraints:

  • 1 ≤ N, Q ≤ 105
  • 1 ≤ L ≤ R ≤ 105

Sample Tests

Input 1
2 2
1 5
3 8
4
9
Output 1
2
0
Input 2
1 1
2 2
2
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.