#abc247h. Ex - Rearranging Problem
Ex - Rearranging Problem
Score : points
问题描述
有个人,依次编号为Person 、Person 、、Person ,他们按照从前往后的顺序排成一排。其中,第个人穿着颜色。
高桥重复了以下操作次:任意选择两个人和,交换Person 和Person 的位置。
在完成次操作后,对于所有满足的整数,从前往数第个人所穿的颜色与相同。
请问,在次操作结束后,有多少种可能的人排列方式?请计算这个排列数对取模的结果。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There are people called Person , Person , , Person , lined up in a row in the order of from the front. Person is wearing Color .
Takahashi repeated the following operation times: choose two People and arbitrarily and swap the positions of Person and Person .
After the operations have ended, the color that the -th person from the front is wearing coincided with , for every integer such that .
How many possible permutations of people after the operations are there? Find the count modulo .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
4 1
1 1 2 1
Sample Output 1
3
Here is a comprehensive list of possible Takahashi's operations and permutations of people after each operation.
- Swap the positions of Person and Person , resulting in a permutation .
- Swap the positions of Person and Person , resulting in a permutation .
- Swap the positions of Person and Person , resulting in a permutation .
Sample Input 2
3 3
1 1 2
Sample Output 2
1
Here is an example of a possible sequence of Takahashi's operations.
- In the -st operation, he swaps the positions of Person and Person , resulting in a permutation .
In the -nd operation, he swaps the positions of Person and Person , resulting in a permutation .
In the -rd operation, he swaps the positions of Person and Person , resulting in a permutation .
Note that, during the sequence of operations, the color that the -th person from the front is wearing does not necessarily coincide with .
Sample Input 3
10 4
2 7 1 8 2 8 1 8 2 8
Sample Output 3
132
update @ 2024/3/10 10:36:32