#P4566. [CTSC2018] 青蕈领主
[CTSC2018] 青蕈领主
Description
Because of a calculus course, Xiao Lü has become very interested in the concept of "continuity". He plans to bring the concept of continuity to sequences of integers. He defines an integer sequence of length to be continuous if and only if the difference between the maximum and minimum elements in the sequence does not exceed . For example, is continuous, while is not.
One day, Xiao Lü’s direct supervisor, Boss Ban, gave him permutations of length . Delighted, Xiao Lü determined, for each permutation, whether each interval is "continuous" as he defined. However, he felt that "continuous" intervals contained within other "continuous" intervals were not good enough. Therefore, for all "continuous" intervals in each permutation with the same right endpoint, he recorded only the length of the longest such "continuous" interval. In other words, for each permutation given by Boss Ban, he recorded for each the length of the longest "continuous" interval whose right endpoint is . Clearly, this length is at least , because all integer sequences of length are continuous.
After finishing all this, Xiao Lü climbed onto his green bed and had a lovely green dream.
But when he woke up the next day, he was shocked to find that all the permutations Boss Ban had given him were gone, leaving only the recorded sets of information. Knowing he was doomed, yet being a curious young man, he still wanted to know: for each set of information, how many length- permutations are consistent with it?
Since Xiao Lü has already given up on treatment, you only need to tell him each answer modulo .
We do not guarantee that there exists at least one permutation consistent with the information, because Xiao Lü is human and can make mistakes.
Input Format
The first line contains two integers , representing the number of permutations Boss Ban gave and the length of each permutation.
The next lines each describe one set of information and contain positive integers. In the -th set, the -th integer from left to right denotes, in the -th permutation, the length of the longest "continuous" interval whose right endpoint is the -th position.
Within each line, if there are multiple numbers, they are separated by a single space.
Output Format
For each set of information, output a single integer on its own line representing the number of possible permutations modulo . Since the computer is doing the calculation, we will not give you a chance to make a mistake.
1 3
1 1 3
2
Hint
Constraints
| 测试点编号 | 特殊性质 | ||
|---|---|---|---|
| 1~2 | 10 | 1 | None |
| 3~4 | 100 | ||
| 5 | 300 | 1 | |
| 6 | 且 | ||
| 7~8 | 100 | None | |
| 9 | 1000 | 1 | 且 |
| 10~12 | 100 | None | |
| 13~16 | 5000 | ||
| 17~20 | 50000 |
For all testdata, $1 \le T \le 100, 1 \le n \le 50000, 1 \le L_{i,j} \le j$.
Some test points have large input size; please be mindful of input speed.
Translated by ChatGPT 5
京公网安备 11011102002149号