Swap Permutation

AtCoder
IDarc176_d
Time4000ms
Memory256MB
Difficulty
You are given a permutation $P=(P_1,P_2,\dots,P_N)$ of $(1,2,\dots,N)$. You will perform the following operation $M$ times: * Choose a pair of integers $(i, j)$ such that $1 \le i < j \le N$, and swap $P_i$ and $P_j$. There are $\left(\frac{N(N-1)}{2}\right)^M$ possible sequences of operations. For each of them, consider the value $\sum_{i=1}^{N-1} |P_i - P_{i+1}|$ after all the operations. Find the sum, modulo $998244353$, of all those values. ## Constraints * $2 \le N \le 2 \times 10^5$ * $1 \le M \le 2 \times 10^5$ * $(P_1,P_2,\dots,P_N)$ is a permutation of $(1,2,\dots,N)$. ## Input The input is given from Standard Input in the following format: $N$ $M$ $P_1$ $P_2$ $\dots$ $P_N$ [samples]
Samples
Input #1
3 1
1 3 2
Output #1
8

There are three possible sequences of operations:

*   Choose $(i,j) = (1,2)$, making $P=(3,1,2)$.
*   Choose $(i,j) = (1,3)$, making $P=(2,3,1)$.
*   Choose $(i,j) = (2,3)$, making $P=(1,2,3)$.

The values of $\sum_{i=1}^{N-1} |P_i - P_{i+1}|$ for these cases are $3$, $3$, $2$, respectively. Thus, the answer is $3 + 3 + 2 = 8$.
Input #2
2 5
2 1
Output #2
1
Input #3
5 2
3 5 1 4 2
Output #3
833
Input #4
20 24
14 1 20 6 11 3 19 2 7 10 9 18 13 12 17 8 15 5 4 16
Output #4
203984325
API Response (JSON)
{
  "problem": {
    "name": "Swap Permutation",
    "description": {
      "content": "You are given a permutation $P=(P_1,P_2,\\dots,P_N)$ of $(1,2,\\dots,N)$. You will perform the following operation $M$ times: *   Choose a pair of integers $(i, j)$ such that $1 \\le i < j \\le N$, and s",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 4000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc176_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a permutation $P=(P_1,P_2,\\dots,P_N)$ of $(1,2,\\dots,N)$. You will perform the following operation $M$ times:\n\n*   Choose a pair of integers $(i, j)$ such that $1 \\le i < j \\le N$, and s...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments