102477: [AtCoder]ABC247 Ex - Rearranging Problem

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

Problem Statement

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

Constraints

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

Input

Input is given from Standard Input in the following format:

$N$ $K$
$c_1$ $c_2$ $\dots$ $c_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 $1$ and Person $2$, resulting in a permutation $(2, 1, 3, 4)$.
  • Swap the positions of Person $1$ and Person $4$, resulting in a permutation $(4, 2, 3, 1)$.
  • Swap the positions of Person $2$ and Person $4$, resulting in a permutation $(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 $1$-st operation, he swaps the positions of Person $1$ and Person $3$, resulting in a permutation $(3, 2, 1)$.
    In the $2$-nd operation, he swaps the positions of Person $2$ and Person $3$, resulting in a permutation $(2, 3, 1)$.
    In the $3$-rd operation, he swaps the positions of Person $1$ and Person $3$, resulting in a permutation $(2, 1, 3)$.

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


Sample Input 3

10 4
2 7 1 8 2 8 1 8 2 8

Sample Output 3

132

Input

题意翻译

给定值域为 $[1, n]$ 的序列 $c_i$,进行 $k$ 次操作:每次选定任意 $i\not= j$ 然后交换 $c_i$ 和 $c_j$。问会形成多少种不同的下标序列,满足没交换之前和所有操作完成之后序列 $c_i$ 不变。

Output

分数:600分

问题描述

有N个人,称为Person 1,Person 2,$\dots$,Person N,按照从前往后的顺序排成一排,顺序为(1,2,$\dots$,N)。Person i穿着Color $c_i$。

Takahashi重复了以下操作$K$次:任意选择两个人Person i和Person j,交换Person i和Person j的位置。

在$K$次操作结束后,从前往后数的第i个人所穿的颜色与$c_i$相同,对于每个满足$1 \leq i \leq N$的整数i。

在$K$次操作之后,有多少种可能的人的排列方式? 找到答案对998244353取模。

约束

  • $2 \leq N \leq 200000$
  • $1 \leq K \leq 10^9$
  • $1 \leq c_i \leq N$
  • 输入中的所有值都是整数。

输入

输入以标准输入的以下格式给出:

$N$ $K$
$c_1$ $c_2$ $\dots$ $c_N$

输出

打印答案。


样例输入1

4 1
1 1 2 1

样例输出1

3

这是Takahashi可能的操作以及每次操作后人排列的全面列表。

  • 交换Person $1$和Person $2$的位置,得到排列$(2, 1, 3, 4)$。
  • 交换Person $1$和Person $4$的位置,得到排列$(4, 2, 3, 1)$。
  • 交换Person $2$和Person $4$的位置,得到排列$(1, 4, 3, 2)$。

样例输入2

3 3
1 1 2

样例输出2

1

这是Takahashi操作序列的示例。

  • 在第1次操作中,他交换了Person $1$和Person $3$的位置,得到排列$(3, 2, 1)$。
  • 在第2次操作中,他交换了Person $2$和Person $3$的位置,得到排列$(2, 3, 1)$。
  • 在第3次操作中,他交换了Person $1$和Person $3$的位置,得到排列$(2, 1, 3)$。

注意,在操作序列中,从前往后的第i个人所穿的颜色不一定会与$c_i$相同。


样例输入3

10 4
2 7 1 8 2 8 1 8 2 8

样例输出3

132

加入题单

算法标签: