#P8391. Interval Jumping
Interval Jumping
Interval Jumping
You are given n intervals. The i-th interval is defined as \( [l_i, r_i] \). When you are currently on interval \( x \), you can jump to an interval \( y \) if and only if
\[
r_x \in [l_y, r_y]
\]
There are q queries. For each query, you are given a starting interval \( s_i \) and a target interval \( t_i \). Your task is to determine the minimum number of jumps required to reach interval \( t_i \) from interval \( s_i \). If it is impossible to reach the target, output impossible
.
inputFormat
The first line contains two integers \( n \) and \( q \) (the number of intervals and the number of queries).
The next \( n \) lines each contain two integers \( l_i \) and \( r_i \), which represents the interval \( [l_i, r_i] \).
The following \( q \) lines each contain two integers \( s_i \) and \( t_i \), denoting a query where you start at interval \( s_i \) and need to jump to interval \( t_i \).
outputFormat
For each query, output a single line containing the minimum number of jumps needed to reach the target interval. If the target is unreachable, output impossible
.
sample
4 3
1 3
2 5
3 6
5 8
1 3
1 4
2 1
1
2
impossible
</p>