#P15740. [JAG 2024 Summer Camp #2] Linear Time Inversion Number

[JAG 2024 Summer Camp #2] Linear Time Inversion Number

题目描述

Given a permutation P\boldsymbol{P} of length NN, Alice uses the inversion number as a measure of how close P\boldsymbol{P} is to the permutation (1,2,,N)(1, 2, \ldots, N), while Bob uses the metric 12i=1NPii\frac{1}{2} \sum_{i=1}^{N} |P_i - i|.

Here, the inversion number is the number of pairs (i,j)(i, j) such that i<ji < j and Pi>PjP_i > P_j.

Given a sequence A=(A1,A2,,AK)\boldsymbol{A} = (A_1, A_2, \ldots, A_K) of length KK, there are (NK)!(N - K)! permutations of length NN that have A\boldsymbol{A} as their prefix.

Find the number of these permutations for which Alice's metric and Bob's metric are equal, and return the result modulo 998,244,353998,244,353.

输入格式

The input is given in the following format:

$$\begin{aligned} &N \ K \\ &A_1 \ A_2 \ \ldots \ A_K \end{aligned} $$
  • 1N200,0001 \leq N \leq 200,000
  • 0KN0 \leq K \leq N
  • 1AiN(1iK)1 \leq A_i \leq N \quad (1 \leq i \leq K)
  • AiAj(ij)A_i \neq A_j \quad (i \neq j)
  • All input values are integers.

输出格式

Output the answer.

5 3
2 3 5
1
10 10
3 1 4 5 9 2 6 8 7 10
0
6 0
132