#P12538. [XJTUPC 2025] 泰拉构史
[XJTUPC 2025] 泰拉构史
Description
This is the first step to solve the mystery, a counting problem.
There is a sequence of length , elements in the sequence are different, and an operation is defined as follows:
- Select a subscript () that satisfies , and swap with in the sequence.
You can perform any number of operations. How many different sequences can you get? Since the answer is large, please output the answer modulo .
Two sequences and are different if and only if there exists such that .
Input Format
There are two lines of input.
The first line contains a positive integer (), which indicates the length of the sequence.
The second line contains positive integers (), separated by a space, which indicates that the initial sequence is . The data guarantees that in the sequence are different.
Output Format
Output a single positive integer, representing the number of possible sequences modulo .
4
1 4 2 3
3
9
11 4 5 14 19 1 9 8 10
6
1
1
1
12
4 3 7 6 8 11 9 10 12 14 13 15
90
Hint
For the first sample, the initial sequence is . Note that the initial sequence is also a possible sequence and needs to be counted.
For the sequence , since , can be swapped, and the sequence after swapping is .
For the sequence , since , can be swapped, and the sequence after swapping is .
It can be proved that for this sequence, there are only the above possibilities for different sequences after any number of operations.
Since the input and output data scale of this question is large, it is recommended to use a faster input and output method.
京公网安备 11011102002149号