#P8505. 「CGOI-2」No voice to cry suffering
「CGOI-2」No voice to cry suffering
Background
Father, your kingdom is collapsing.
Father, your people are leaving.
Father, but you said I should not have a voice to cry for suffering.
So I can do nothing, so I fall apart alone.
Problem Description
There are infected people in front of the container. These infected people stand in a line, numbered from to in order. The infection depth of the -th infected person is .
The container starts from the -th infected person and walks towards the -th infected person, passing through the infected people from to in order. The container will kill all infected people it passes. However, if it kills two infected people whose indices are consecutive and whose infection depths are strictly increasing, then it will skip the next infected person (if the next one exists).
Let denote the number of infected people killed when the container starts from position (all are pairwise independent). For example, if there are five infected people with infection depths:
2 6 4 5 1
then the corresponding sequence is .
You do not know the infection depth of each infected person. You only know the values of for pairs. Please output, modulo , the number of different sequences that satisfy the conditions.
Two sequences are different if and only if there exists such that .
Input Format
The first line contains two integers .
In the next lines, each line contains a pair , meaning .
Note that the input may contain incorrect pairs, and you need to ignore them by yourself. Specifically, if a pair makes it impossible to have any valid sequence after considering all valid pairs among and this pair, then this pair is invalid, and you should not consider it when computing the answer.
Output Format
Output lines, one number per line.
The first line is the answer modulo when no pairs are considered.
The -th line () is the answer modulo after considering all valid pairs among .
3 3
1 5
1 1
1 0
2
2
1
1
5 2
2 1
4 5
4
3
3
Hint
Explanation for Sample 1
Initially, the valid sequences are and .
Constraint 1: None of the initial sequences satisfies constraint 1, so ignore this constraint.
Constraint 2: Only satisfies the constraint.
Constraint 3: Only satisfies the constraint. Together with constraint 2, there is no valid sequence, so ignore this constraint.
Constraints and Notes
For of the testdata, .
For of the testdata, .
For another of the testdata, .
For of the testdata, $1 \leq n \leq 10^{11}, 0 \leq m \leq 5\times 10^4, 0 \leq |y| \leq n, 1 \leq x < n$.
Translated by ChatGPT 5