#P2650. 弹幕考察

弹幕考察

Description

zeromaker has conducted in-depth research on controlling his field of view for danmaku. Each danmaku appears in zeromaker’s field of view during a specific time interval, and is invisible outside that interval. In zeromaker’s opinion, the more danmaku are within the field of view, the harder the stage becomes, because this means @#¥%. Now, to evaluate the difficulty of a stage, he has already learned when each danmaku appears within his field of view. He wants to know, within a given time period, how many distinct danmaku have ever appeared in his field of view.

Note: Here, “seconds” are treated as time instants. A danmaku is considered to have appeared in the field of view if and only if the observation interval and the danmaku’s appearance interval overlap with positive length; endpoint-only contact (for example, a danmaku ends at second 22 and the observation starts at second 22) does not count as appearing.

Description

The first line contains two integers nn, mm, indicating there are nn danmaku in total, and zeromaker has mm queries.

The next nn lines each contain two integers aa, bb, meaning this danmaku appears in zeromaker’s field of view starting at second aa and lasts for bb seconds. The following mm lines each contain two integers xx, yy, meaning starting from second xx, over yy seconds, ask how many danmaku have appeared at any time in that interval.

Note: Here, “seconds” are time instants. A danmaku is considered to have appeared in the field of view if and only if the observation interval and the danmaku’s appearance interval overlap with positive length; endpoint-only contact (e.g., the danmaku ends at second 22 while the observation starts at second 22) does not count as appearing.

Input Format

The first line contains two integers nn, mm.

The next nn lines each contain two integers aa, bb, where the danmaku appears at second aa and lasts for bb seconds.

The next mm lines each contain two integers xx, yy, asking: from second xx, over yy seconds, how many danmaku have ever appeared.

Output Format

Output mm lines, where each line is the answer to one of zeromaker’s queries.

3 2
2 5
0 10
5 8
0 6
8 2
3
2
1 2
0 10
9 1
10 1
1 
0

Hint

Sample 1 explanation:

       0  1  2  3  4  5  6  7  8  9 10 11 12 13
弹幕1        |--------------|
弹幕2  |-----------------------------|
弹幕3                 |-----------------------|
视野1  |-----------------|
视野2                          |-----|

Sample 2 explanation:

       0  1  2  3  4  5  6  7  8  9 10 11
弹幕1  |-----------------------------|
视野1                             |--|
视野2                                |--|

Constraints:

  • 30%30\% of the testdata: n,m103n, m \le 10^3.
  • 100%100\% of the testdata: 1n,m1051 \le n, m \le 10^5, 0x,y,a,b23110 \le x, y, a, b \le 2^{31} - 1.

Translated by ChatGPT 5