#P7781. 「MCOI-Zero / AC6-M07」Selumna Peak
「MCOI-Zero / AC6-M07」Selumna Peak
Description
You are given a permutation of .
For each , consider the following sequence of operations:
- First, choose a subsequence in (it can be empty).
- Then, reorder the numbers in this subsequence.
Compute the total sum of inversion counts of all permutations produced by all different operation sequences, modulo .
Two operation sequences are different if and only if the chosen subsequence is different, or the reordering method is different.
The operations will not actually be applied to the permutation.
Input Format
The first line contains an integer .
The next line contains numbers, representing the permutation .
Output Format
Output lines, one number per line, representing the value (modulo ) of the total sum of inversion counts of all permutations produced by all different operation sequences for the prefix .
3
1 2 3
0
1
14
8
3 2 4 1 6 8 7 5
16
39
132
476
2842
21137
172002
1427424
Hint
Explanation for Sample 1:
- For , no inversions can be produced, so the answer is .
- For , only one operation sequence can produce , so the answer is .
- For :
- There are operation sequences that produce .
- There are operation sequences that produce .
- There are operation sequences that produce .
- There is operation sequence that produces .
- There is operation sequence that produces .
- There are operation sequences that produce .
- The answer is $0\times 8+1\times 2+1\times 2+2\times 1+2\times 1+2\times 3=14$.
Explanation for Sample 2:
- For , there are only two operation sequences, and the permutations produced both have inversions, so the answer is .
- For , there are operation sequences that produce , and operation sequence that produces . The answer is .
Constraints:
- Subtask 1 (10%): .
- Subtask 2 (20%): .
- Subtask 3 (20%): .
- Subtask 4 (20%): .
- Subtask 5 (30%): no special constraints.
For of the testdata, .
idea: Sol1, solution: Sol1, code: Sol1, data: Sol1
Translated by ChatGPT 5
京公网安备 11011102002149号