#P7968. Maximum Investigations Required

    ID: 21152 Type: Default 1000ms 256MiB

Maximum Investigations Required

Maximum Investigations Required

There are n suspects, each with an uncertain height range \( [l_i, r_i] \). Because of the ambiguity of their heights, only the range for each suspect is known.

An investigation can be carried out on a contiguous group of suspects (with indices in \( [a,b] \)) provided that the height ranges of the suspects in that group are pairwise disjoint (i.e. no two intervals intersect). Note that since the intervals are closed, two intervals \( [l_i, r_i] \) and \( [l_j, r_j] \) intersect if they share at least one common point.

If a suspect is involved in any investigation, the witness can immediately make the correct judgment about that suspect. Given that the suspects to be considered lie in the index range \( [p_i,q_i] \), determine the maximum number of investigations that might be required. In other words, if one wants to cover all suspects in \( [p_i,q_i] \) with valid investigation groups, what is the minimum number of rounds needed? This value is equal to the maximum number of overlapping intervals among the suspects in that range.

inputFormat

The first line contains two integers n and q — the number of suspects and the number of queries.

The next n lines each contain two integers \( l_i \) and \( r_i \) representing the height range of the i-th suspect.

The following q lines each contain two integers \( p_i \) and \( q_i \) representing a query. Here, suspects are numbered from 1 to n, and each query considers the suspects in the index range \( [p_i,q_i] \).

outputFormat

For each query, output a single integer on a new line — the maximum number of investigations required (i.e. the maximum number of overlapping intervals among the suspects in the query range).

sample

3 3
1 3
2 5
4 6
1 1
1 2
1 3
1

2 2

</p>