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
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.