#arc176d. D - Swap Permutation
D - Swap Permutation
Score: points
问题陈述
给定一个排列 ( P = (P_1, P_2, \dots, P_N) ),它是 ( (1, 2, \dots, N) ) 的一个排列。你需要执行以下操作 ( M ) 次:
- 选择一对整数 ( (i, j) ),使得 ( 1 \le i < j \le N ),并且交换 ( P_i ) 和 ( P_j )。
有 ( \left(\frac{N(N-1)}{2}\right)^M ) 种可能的操作序列。对于每一种序列,在所有操作之后考虑值 ( \sum_{i=1}^{N-1} |P_i - P_{i+1}| )。找出所有这些值的总和,对 ( 998244353 ) 取模。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given a permutation of . You will perform the following operation times:
- Choose a pair of integers such that , and swap and .
There are possible sequences of operations. For each of them, consider the value after all the operations. Find the sum, modulo , of all those values.
Constraints
- is a permutation of .
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3 1
1 3 2
Sample Output 1
8
There are three possible sequences of operations:
- Choose , making .
- Choose , making .
- Choose , making .
The values of for these cases are , , , respectively. Thus, the answer is .
Sample Input 2
2 5
2 1
Sample Output 2
1
Sample Input 3
5 2
3 5 1 4 2
Sample Output 3
833
Sample Input 4
20 24
14 1 20 6 11 3 19 2 7 10 9 18 13 12 17 8 15 5 4 16
Sample Output 4
203984325