atcoder#ACL1E. Shuffle Window
Shuffle Window
Score : points
Problem Statement
Given are a permutation of and an integer . Maroon performs the following operation for in this order:
- Shuffle uniformly randomly.
Find the expected value of the inversion number of the sequence after all the operations are performed, and print it modulo .
More specifically, from the constraints of this problem, it can be proved that the expected value is always a rational number, which can be represented as an irreducible fraction , and that the integer that satisfies $R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353$ is uniquely determined. Print this .
Here, the inversion number of a sequence is defined to be the number of ordered pairs that satisfy .
Constraints
- is a permutation of .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
...
Output
Print the expected value modulo .
3 2
1 2 3
1
The final sequence is one of , , , , each with probability . Their inversion numbers are respectively, so the expected value is .
10 3
1 8 4 9 2 3 7 10 5 6
164091855