#abc247h. Ex - Rearranging Problem

Ex - Rearranging Problem

Score : 600600 points

问题描述

NN个人,依次编号为Person 11、Person 22\dots、Person NN,他们按照从前往后的顺序(1,2,,N)(1,2,\dots,N)排成一排。其中,第ii个人穿着颜色cic_i

高桥重复了以下操作KK次:任意选择两个人iijj,交换Person ii和Person jj的位置。

在完成KK次操作后,对于所有满足1iN1 \leq i \leq N的整数ii,从前往数第ii个人所穿的颜色与cic_i相同。

请问,在KK次操作结束后,有多少种可能的人排列方式?请计算这个排列数对998244353998244353取模的结果。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN people called Person 11, Person 22, \dots, Person NN, lined up in a row in the order of (1,2,,N)(1,2,\dots,N) from the front. Person ii is wearing Color cic_i.
Takahashi repeated the following operation KK times: choose two People ii and jj arbitrarily and swap the positions of Person ii and Person jj.
After the KK operations have ended, the color that the ii-th person from the front is wearing coincided with cic_i, for every integer ii such that 1iN1 \leq i \leq N.
How many possible permutations of people after the KK operations are there? Find the count modulo 998244353998244353.

Constraints

  • 2N2000002 \leq N \leq 200000
  • 1K1091 \leq K \leq 10^9
  • 1ciN1 \leq c_i \leq N
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

c1c_1 c2c_2 \dots cNc_N

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 11 and Person 22, resulting in a permutation (2,1,3,4)(2, 1, 3, 4).
  • Swap the positions of Person 11 and Person 44, resulting in a permutation (4,2,3,1)(4, 2, 3, 1).
  • Swap the positions of Person 22 and Person 44, resulting in a permutation (1,4,3,2)(1, 4, 3, 2).

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 11-st operation, he swaps the positions of Person 11 and Person 33, resulting in a permutation (3,2,1)(3, 2, 1).
    In the 22-nd operation, he swaps the positions of Person 22 and Person 33, resulting in a permutation (2,3,1)(2, 3, 1).
    In the 33-rd operation, he swaps the positions of Person 11 and Person 33, resulting in a permutation (2,1,3)(2, 1, 3).

Note that, during the sequence of operations, the color that the ii-th person from the front is wearing does not necessarily coincide with cic_i.

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