No.2327 Inversion Sum
問題文最終更新日: 2023-05-24 08:38:08
English (AI translation)
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence.
Back to the original
MMA Contest 015
(順位表)
の他の問題:
Problem Statement
Consider a permutation of $(1, 2, \cdots, N)$. This permutation must satisfy $M$ constraints, where the $i$-th constraint is as follows.
- $P_i$ is located at the $K_i$-th position from the front
Input
$N\ M$ $P_1\ K_1$ $P_2\ K_2$ $\ \ \ \ \vdots$ $P_M\ K_M$
Constraints
- $1 \leq N \leq 10 ^ 5$
- $0 \leq M \leq N$
- $1 \leq P_i, K_i \leq N$
- If $i \neq j$, then $P_i \neq P_j$ and $K_i \neq K_j$
- All input values are integers
Output
Output the result on $1$ line.
Sample
Sample 1
Input
3 1 1 2
Output
3
The permutations satisfying the conditions are the $2$ permutations $\{2, 1, 3\}, \{3, 1, 2\}$, whose inversion numbers are $1, 2$ respectively, so output $1 + 2 = 3$.
Sample 2
Input
5 0
Output
600
Sample 3
Input
20 4 19 3 7 5 11 15 3 8
Output
936714253
Note that the output must be given $\! \! \! \mod 998244353$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
sepa38