#P6035. Ryoku 的逆序对
Ryoku 的逆序对
Description
Ryoku has a permutation of the positive integers .
She tells you a sequence . For each number , among all , there are exactly numbers that can form an inversion pair with (an inversion pair is defined as follows: a pair that satisfies and is called an inversion pair).
Unfortunately, some positions in the sequence Ryoku gave you are damaged. You want to know how many possible permutations can satisfy the condition.
Please output the answer and construct the lexicographically smallest permutation (for permutations and , if there exists a position such that and , then is lexicographically smaller than ).
Input Format
The input contains two lines.
The first line contains an integer .
The second line contains integers, which form the sequence . If , it means this position is damaged.
Output Format
The output contains two lines.
The first line contains an integer, the number of possible permutations , taken modulo .
The second line contains integers, the lexicographically smallest permutation that satisfies the condition. If the answer in the first line is , then the second line does not need to be output.
5
0 3 0 0 0
1
1 5 2 3 4
5
0 3 -1 0 0
3
1 5 2 3 4
5
0 3 -1 0 1
0
Hint
[Sample 1 Explanation]
For , there are inversion pairs , a total of three pairs.
[Sample 2 Explanation]
The permutations that satisfy the condition are: $\{1, 5, 4, 2, 3\}, \{1, 5, 3, 2, 4\}, \{1, 5, 2, 3, 4\}$. There are three in total, and the lexicographically smallest is .
[Constraints]
For of the testdata, .
For another of the testdata, .
For another of the testdata, .
For another of the testdata, .
For another of the testdata, .
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号