#P6349. [PA 2011] Kangaroos

    ID: 7109 远端评测题 5000ms 500MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>2011莫队O2优化K-D TreePA(波兰)

[PA 2011] Kangaroos

Problem Description

You are given a sequence aa of length nn. The ii-th element is an interval [li,ri][l_i, r_i].

There are mm queries. Each query gives A,BA, B. Find the longest subarray (i.e., a contiguous segment of this sequence) such that every interval in this subarray intersects with [A,B][A, B]. Output the length of this longest subarray.

Input Format

The first line contains two 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 A,BA, B, describing one query.

Output Format

Output mm lines. Each line contains one integer, the answer to the corresponding query.

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

Hint

Constraints: 1n5×1041 \le n \le 5 \times 10^4, 1m2×1051 \le m \le 2 \times 10^5, 1liri1091 \le l_i \le r_i \le 10^9, 1AB1091 \le A \le B \le 10^9.

Translated by ChatGPT 5