#P4223. 期望逆序对

    ID: 3162 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>树状数组枚举,暴力期望矩阵乘法

期望逆序对

Description

The monastery led by mcfx attempts to summon the legendary “memetic master” WXH through an ancient ritual array. After preparing all the summoning tools, mcfx activates the array to the clatter of many keyboards.

Suddenly, heaven and earth darken, and lightning strikes the center of the array. A golden beam descends from the sky, with golden code drifting in midair. Soon, a login interface appears. Upon careful inspection, mcfx sees the following text:

"WXHCoder is a problem bank that contains every problem from the past to the future. If you want to log into it, you must solve the following problem."

The problem is as follows: You are given a permutation of length nn. There are kk operations. In each operation, two distinct numbers are chosen uniformly at random and swapped. Find the expected number of inversions multiplied by (n2)k{{n}\choose{2}}^k.

mcfx discovered that the Constraints are n,k1020010910n, k \le 10^{20010910}, so he decides to first explore smaller n,kn, k.

(n2){n}\choose{2} denotes the number of ways to choose two from nn balls.

Input Format

The first line contains two integers n,kn, k.

The second line contains a permutation of 11 through nn.

Output Format

Output the expected number of inversions multiplied by (n2)k{{n}\choose{2}}^k modulo 109+710^9+7.

5 4 
1 5 4 3 2
50000

Hint

n500000,k109n \le 500000, k \le 10^9.

Translated by ChatGPT 5