#P11028. [COTS 2020] 龙猫 Totoro
[COTS 2020] 龙猫 Totoro
Background
Translated from Izborne Pripreme 2020 (Croatian IOI/CEOI Team Selection) D2T3。。
Problem Description
You are given permutations of 。
Find the expected number of inversions of a permutation in the permutation group , where the binary operation is permutation composition, and for all , we have 。
More specifically, we define 。
The group is an algebraic structure satisfying the following properties:
- Closure: for all , we have ;
- Associativity: for all , we have ;
- Identity element: there exists such that for all , ;
- Inverse element: for all , there exists such that 。
Define as the number of inversions of , i.e. $\displaystyle \mathcal{L}(\pi)=\sum_{1\le i\lt j\le n}[\pi(i)\gt \pi(j)]$。Compute $\displaystyle \frac{1}{|S|}\sum_{\pi \in S} \mathcal{L}(\pi)$。
Output the answer modulo 。
Input Format
The first line contains two positive integers 。
The next lines each contain positive integers describing 。
Output Format
Output one integer: the answer modulo 。
1 3
2 3 1
333333337
2 5
4 2 1 3 5
2 5 4 3 1
5
1 9
3 4 5 6 7 8 1 9 2
300000017
Hint
Sample Explanation
- Sample : 。The expected number of inversions is 。
- Sample : It can be proven that , meaning that contains all permutations of 。
- Sample : Here 。The true value of the answer is 。
Constraints
For of the testdata, it is guaranteed that:
- ;
- ;
- is a permutation of 。
| Subtask ID | Special Property | Score | ||
|---|---|---|---|---|
| None | ||||
| Yes | ||||
| None | ||||
Special Property: for all , there exists a permutation of such that $\pi_i(a_1)=a_2,\pi_{i}(a_2)=a_3,\cdots,\pi_i(a_n)=a_1$。
Translated by ChatGPT 5