#P11028. [COTS 2020] 龙猫 Totoro

    ID: 12441 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2020O2优化群论置换COCI(克罗地亚)

[COTS 2020] 龙猫 Totoro

Background

Translated from Izborne Pripreme 2020 (Croatian IOI/CEOI Team Selection) D2T3。1s,0.5G\texttt{1s,0.5G}

Problem Description

You are given KK permutations π1,π2,,πK\pi_1,\pi_2,\cdots,\pi_K of 1N1 \sim N

Find the expected number of inversions of a permutation in the permutation group G(S,)G(S,\circ), where the binary operation \circ is permutation composition, and for all 1iK1 \le i \le K, we have πiS\pi_i \in S

More specifically, we define (πτ)(i)=π(τ(i))(\pi \circ \tau)(i) = \pi(\tau(i))

The group G(S,)G(S,\circ) is an algebraic structure satisfying the following properties:

  • Closure: for all a,bSa,b \in S, we have abSa \circ b \in S
  • Associativity: for all a,b,cSa,b,c \in S, we have (ab)c=a(bc)(a \circ b) \circ c = a \circ (b \circ c)
  • Identity element: there exists eSe \in S such that for all aSa \in S, ae=ea=aa \circ e = e \circ a = a
  • Inverse element: for all aSa \in S, there exists bSb \in S such that ab=ba=ea \circ b = b \circ a = e

Define L(π)\mathcal{L}(\pi) as the number of inversions of π\pi, 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 (109+7)(10^9+7)

Input Format

The first line contains two positive integers K,NK, N

The next KK lines each contain NN positive integers describing πi\pi_i

Output Format

Output one integer: the answer modulo (109+7)(10^9+7)

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 11: S={[2,3,1],[3,1,2],[1,2,3]}S=\{[2,3,1],[3,1,2],[1,2,3]\}。The expected number of inversions is 1+2+03=43\frac{1+2+0}{3}=\frac{4}{3}
  • Sample 22: It can be proven that S=5!|S| = 5!, meaning that SS contains all permutations of 151 \sim 5
  • Sample 33: Here S=20|S|=20。The true value of the answer is 14910\frac{149}{10}

Constraints

For 100%100\% of the testdata, it is guaranteed that:

  • 1K101 \le K \le 10
  • 1N25001 \le N \le 2\, 500
  • πi\pi_i is a permutation of 1N1 \sim N
Subtask ID NN\le KK\le Special Property Score
1 1 99 10 10 None 7 7
2 2 25002\,500 11 Yes 8 8
3 3 25002\, 500 None 25 25
4 4 1010 60 60

Special Property: for all 1iK1 \le i \le K, there exists a permutation aa of 1N1 \sim N 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