P5367 [Template] Cantor Expansion
Description
Find the rank of a given permutation of $1\sim N$ among all permutations of $1\sim N$. Output the result modulo $998244353$.
Input Format
The first line contains a positive integer $N$.
The second line contains $N$ positive integers, representing a permutation of $1\sim N$.
Output Format
Output one non-negative integer, the answer modulo $998244353$.
Explanation/Hint
For $10\%$ of the testdata, $1\le N\le 10$.
For $50\%$ of the testdata, $1\le N\le 5000$.
For $100\%$ of the testdata, $1\le N\le 1000000$.
Translated by ChatGPT 5