#P6349. [PA 2011] Kangaroos

[PA 2011] Kangaroos

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