AtCoder Beginner Contest 380
G
Another Shuffle Window
AtCoder
⌀ 1995
原题
翻译中…

Problem Statement

翻译中…

You are given a permutation $P$ of $(1,2,\dots,N)$ and an integer $K$.

翻译中…

Find the expected value, modulo $998244353$, of the inversion number of $P$ after performing the following operation:

翻译中…
  • First, choose an integer $i$ uniformly at random between $1$ and $N - K + 1$, inclusive.
  • Then, shuffle $P_i, P_{i+1}, \dots, P_{i+K-1}$ uniformly at random.
翻译中…

What is the inversion number? The inversion number of a sequence $(A_1, A_2, \dots, A_N)$ is the number of integer pairs $(i, j)$ satisfying $1 \le i < j \le N$ and $A_i > A_j$.

翻译中…

What does "expected value modulo $998244353$" mean? It can be proved that the sought expected value is always rational. Under the constraints of this problem, when this value is represented as an irreducible fraction $\frac{P}{Q}$, it can also be proved that $Q \not\equiv 0 \pmod{998244353}$. Thus, there is a unique integer $R$ satisfying $R \times Q \equiv P \pmod{998244353}, \ 0 \le R < 998244353$. Report this integer $R$.

翻译中…

Constraints

翻译中…
  • All input values are integers.
  • $1 \le K \le N \le 2 \times 10^5$
  • $P$ is a permutation of $(1,2,\dots,N)$.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N K
P_1 P_2 \dots P_N

翻译中…

Output

翻译中…

Print the answer in one line.

翻译中…

样例

Input #1
4 2
1 4 2 3
Output #1
166374061
The operation changes the permutation $P$ into the following: - $(1,4,2,3)$ ... probability $1/2$ - $(4,1,2,3)$ ... probability $1/6$ - $(1,2,4,3)$ ... probability $1/6$ - $(1,4,3,2)$ ... probability $1/6$ The expected value of the inversion number is $\displaystyle 2 \times \frac{1}{2} + 3 \times \frac{1}{6} + 1 \times \frac{1}{6} + 3 \times \frac{1}{6} = \frac{13}{6}$. $\displaystyle \frac{13}{6}$ modulo $998244353$ is $166374061$, so print this number.
Input #2
1 1
1
Output #2
0
Input #3
10 6
7 4 10 5 6 1 8 2 3 9
Output #3
499122200
题目信息
题号
abc380_g
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。