#P5367. 【模板】康托展开

    ID: 6103 远端评测题 1500ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>线段树平衡树树状数组康托展开

【模板】康托展开

Problem Description

Find the rank of a given permutation of 1N1\sim N among all permutations of 1N1\sim N. Output the result modulo 998244353998244353.

Input Format

The first line contains a positive integer NN.

The second line contains NN positive integers, representing a permutation of 1N1\sim N.

Output Format

Output one non-negative integer, the answer modulo 998244353998244353.

3
2 1 3
3
4
1 2 4 3
2

Hint

For 10%10\% of the testdata, 1N101\le N\le 10.

For 50%50\% of the testdata, 1N50001\le N\le 5000.

For 100%100\% of the testdata, 1N10000001\le N\le 1000000.

Translated by ChatGPT 5