CF793F.Julia the snail
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
After hard work Igor decided to have some rest.
He decided to have a snail. He bought an aquarium with a slippery tree trunk in the center, and put a snail named Julia into the aquarium.
Igor noticed that sometimes Julia wants to climb onto the trunk, but can't do it because the trunk is too slippery. To help the snail Igor put some ropes on the tree, fixing the lower end of the i-th rope on the trunk on the height l__i above the ground, and the higher end on the height r__i above the ground.
For some reason no two ropes share the same position of the higher end, i.e. all r__i are distinct. Now Julia can move down at any place of the trunk, and also move up from the lower end of some rope to its higher end. Igor is proud of his work, and sometimes think about possible movements of the snail. Namely, he is interested in the following questions: «Suppose the snail is on the trunk at height x now. What is the highest position on the trunk the snail can get on if it would never be lower than x or higher than y?» Please note that Julia can't move from a rope to the trunk before it reaches the higher end of the rope, and Igor is interested in the highest position on the tree trunk.
Igor is interested in many questions, and not always can answer them. Help him, write a program that answers these questions.
经过一番辛苦工作后,伊戈尔决定休息一下。
他决定养一只蜗牛。他买了一个水族箱,其中心有一根光滑的树干,并将一只名叫朱莉娅的蜗牛放入了水族箱中。
伊戈尔注意到,朱莉娅有时想爬上这根树干,但由于树干太滑而无法成功。为了帮助这只蜗牛,伊戈尔在树干上绑了一些绳子:第 i 根绳子的下端固定在离地面高度为 li 的位置,上端固定在离地面高度为 ri 的位置。
出于某种原因,任意两根绳子的上端高度均不相同,即所有 ri 互不相等。现在,朱莉娅可以在树干上的任意位置向下爬行;同时,她也可以从某根绳子的下端向上爬至该绳子的上端。伊戈尔为自己的工作感到自豪,有时会思考蜗牛可能的运动方式。具体而言,他关心如下问题:「假设蜗牛当前位于树干上高度为 x 的位置。若蜗牛在整个运动过程中始终不高于 y、不低于 x,那么它最终所能到达的树干上的最高位置是多少?」请注意,朱莉娅只有到达某根绳子的上端之后,才能从该绳子转移到树干上;此外,伊戈尔所关心的只是蜗牛在树干上所能到达的最高位置。
伊戈尔提出了很多此类问题,却并不总能自行解答。请帮助他编写一个程序来回答这些问题。
输入格式
The first line contains single integer n (1 ≤ n ≤ 100000) — the height of the trunk.
The second line contains single integer m (1 ≤ m ≤ 100000) — the number of ropes.
The next m lines contain information about the ropes.
The i-th of these lines contains two integers l__i and r__i (1 ≤ l__i ≤ r__i ≤ n) — the heights on which the lower and the higher ends of the i-th rope are fixed, respectively. It is guaranteed that all r__i are distinct.
The next line contains single integer q (1 ≤ q ≤ 100000) — the number of questions.
The next q lines contain information about the questions.
Each of these lines contain two integers x and y (1 ≤ x ≤ y ≤ n), where x is the height where Julia starts (and the height Julia can't get lower than), and y is the height Julia can't get higher than.
第一行包含一个整数 n(1≤n≤100000)——树干的高度。
第二行包含一个整数 m(1≤m≤100000)——绳子的数量。
接下来的 m 行描述了这些绳子的信息。
其中第 i 行包含两个整数 li 和 ri(1≤li≤ri≤n),分别表示第 i 根绳子的下端和上端所固定的海拔高度。保证所有 ri 互不相同。
接下来一行包含一个整数 q(1≤q≤100000)——询问的数量。
接下来的 q 行描述了这些询问。
每行包含两个整数 x 和 y(1≤x≤y≤n),其中 x 是 Julia 的起始高度(也是 Julia 不能下降到的最低高度),y 是 Julia 不能上升到的最高高度。
输出格式
For each question print the maximum reachable for Julia height.
对于每个问题,输出朱莉娅能够达到的最大高度。
输入输出样例
输入#1
8 4 1 2 3 4 2 5 6 7 5 1 2 1 4 1 6 2 7 6 8
输出#1
2 2 5 5 7
输入#2
10 10 3 7 1 4 1 6 5 5 1 1 3 9 7 8 1 2 3 3 7 10 10 2 4 1 7 3 4 3 5 2 8 2 5 5 5 3 5 7 7 3 10
输出#2
2 7 3 3 2 2 5 3 7 10
说明/提示
The picture of the first sample is on the left, the picture of the second sample is on the right. Ropes' colors are just for clarity, they don't mean anything.

第一个样例的图片在左侧,第二个样例的图片在右侧。绳子的颜色仅用于清晰显示,不表示任何含义。

输入解题思路,AI测评打分。不知道怎么写?