QOJ.ac

QOJ

Time Limit: 4 s Memory Limit: 32 MB Total points: 10

#10390. Kangaroos [A]

统计

Byteasar, who is interested in wildlife photography, is planning a trip to Australia. He has started preparing his photographic equipment for taking pictures of kangaroos, and has to decide what items to pack. His equipment includes an extensive collection of photographic lenses with varying characteristics for different angles of view and focusing abilities. The best quality of pictures of animals, such as kangaroos, is achieved when the distance between the camera and the animal is within the optimal range of the lens.

Byteasar's trip passes through a sequence of access points for wildlife observation and photography. The Australian guides gave Byteasar a detailed description of these observation points-in particular, the distances at which kangaroos can be expected.

Obviously, not all the lenses from Byteasar's large collection will fit in his luggage, so some decisions must be made. Since Byteasar wishes to keep his lens-changes to a minimum, he wants to find-for each of the lenses-the longest contiguous sequence of observation points on the trip for which that lens is suitable. A lens is suitable for a given observation point if there exists a distance from the range of expected distances that lies within the optimal range of that lens.

Input Format

The first line of the standard input contains two integers, $n$ and $m$ ($1 ≤ n ≤ 50\,000$, $1 ≤ m ≤ 200\,000$), where n is the number of observation points on the trip and $m$ is the number of lenses in Byteasar's collection.

The next $n$ lines describe the access points for wildlife observation and photography on Byteasar's trip. Each of these lines contains two integers, $a_{i}$ and $b_{i}$ ($1 ≤ a_{i} ≤ b_{i} ≤ 10^{9}$), indicating that at the $i$-th observation point kangaroos can appear at a distance of $a_{i}$ to $b_{i}$ bytean feet, inclusive.

The next $m$ lines describe the lenses. Each of these lines contains two integers, $c_{j}$ and $d_{j}$ ($1 ≤ c_{j} ≤ d_{j} ≤ 10^{9}$), indicating that the $j$-th lens works best for kangaroos that are at a distance from $c_{j}$ to $d_{j}$ bytean feet from the camera, inclusive.

Output Format

The standard output should consist of $m$ lines containing exactly one integer each. The $j$-th output line indicates the number of observation points in the longest contiguous segment of the trip where the $j$-th lens can be used by Byteasar. The lenses are numbered according to their order in the input file.

Example

Input

3 3
2 5
1 3
6 6
3 5
1 10
7 9

Output

2
3
0

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.