#P9426. [蓝桥杯 2023 国 B] 抓娃娃

[蓝桥杯 2023 国 B] 抓娃娃

Problem Description

Xiaoming took nn line segments to practice playing a claw machine. He laid all the segments on the number line. For the ii-th segment, its left endpoint is at lil_i and its right endpoint is at rir_i. Xiaoming uses mm intervals to “frame” these segments. The range of the ii-th interval is [Li,Ri][L_i, R_i]. If at least half of a segment’s length is contained in some interval, then the segment is considered to be framed by that interval. Please compute how many segments are framed by each interval.

Input Format

The input has a total of n+m+1n + m + 1 lines.

The first line contains two positive integers n,mn, m.

The next nn lines each contain two integers li,ril_i, r_i.

The next mm lines each contain two integers Li,RiL_i, R_i.

Output Format

Output a total of mm lines, each containing one integer.

3 2
1 2
1 3
3 4
1 4
2 4
3
2

Hint

Test Case Scale and Conventions

  • For 20%20\% of the testdata, n,m103n, m \le 10^3 is guaranteed.
  • For 100%100\% of the testdata, n,m105n, m \le 10^5 is guaranteed, li<ril_i < r_i, 0<li,ri,Li,Ri1060 < l_i, r_i, L_i, R_i \le 10^6, and max{rili}min{RiLi}\max \{r_i − l_i\} \le \min \{R_i − L_i\}.

Problem H of Group B (C/C++), College Division, Finals of the 14th Lanqiao Cup Software Contest.

Translated by ChatGPT 5