Riding to the Destination (APCS 2024-10 Expert)
2.0s 256MStart at \(0\) and reach \(m\) using buses. Bus \(i\) runs from \(l_i\) to \(r_i\). At position \(x\) you may board it if \(l_i\le x<r_i\), and must get off at \(r_i\). There is no other movement. Count bus-ID sequences reaching \(m\), modulo \(p\). Buses with identical endpoints are still distinct.
Input Format
Read \(n,m,p\), then all starting points, then all corresponding ending points.
Output Format
Print the count modulo \(p\).
Constraints
\(1\le n\le200000\), \(1\le m\le10^9\), \(1\le p\le10^9+9\); \(0\le l_i<r_i\le m\).
Scoring
- 20 points: \(n,m\le100\).
- 40 points: \(m\le100000\).
- 40 points: No additional restrictions.
Each scored test is worth 5 points.
Sample Input 1
5 9 11
0 4 0 3 5
4 6 6 7 9
Sample Output 1
7
Sample Input 2
6 8 4
0 1 2 3 5 6
3 6 6 6 8 8
Sample Output 2
2
Source
APCS 2024-10 public archive version: o714。
Log in to write and submit code.
Log in