#P9493. 「SFCOI-3」进行一个列的排
「SFCOI-3」进行一个列的排
Background

(In fact, this problem was originally called I must say No, but for some obvious reasons the title was changed /kk.)
You must say Yes.
(The background image comes from Phigros artwork. If there is any infringement, please inform the problem setter.)
Problem Description
Little R has a permutation of length . In other words, contains the numbers from to , and among these numbers, each number appears in exactly once.
Little R has constraints. The -th constraint is described by apositive integer , meaning that there exists at least one interval of length (i.e. ) such that .
Little R has lost the permutation , but fortunately she still remembers these constraints. Please help her find how many initial permutations are valid. Output the answer modulo .
Input Format
This problem has multiple test cases in each test point.
The first line contains an integer , the number of test cases. For each test case:
- The first line contains an integer .
- The second line contains integers, representing in order.
Output Format
Output lines. Each line contains one integer, the answer.
4
4
1 1 3 3
5
2 1 3 3 4
6
1 1 2 5 4 5
10
3 2 3 4 7 6 8 8 8 9
4
12
8
96
Hint
Definitions
- The of a sequence is the smallest non-negative integer that does not appear in it. For example, , , .
Constraints
- Subtask 0 (10 pts): .
- Subtask 1 (30 pts): .
- Subtask 2 (15 pts): .
- Subtask 3 (45 pts): no special constraints.
For all testdata, , , .
Translated by ChatGPT 5