#abc330g. G - Inversion Squared
G - Inversion Squared
Score : points
问题描述
给定一个长度为 的序列 。序列 中的每个元素要么是 ,要么是介于 和 之间的整数,并且从 到 的每个整数最多出现一次。
若一个排列 满足 ,则称其为 良排列。请计算所有良排列的倒序数平方和,结果对 取模。
排列 的倒序数是指满足条件 且 的整数对 的数量。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a sequence of length . Each element of is either or an integer between and , and each integer from to is contained at most once.
A permutation of is called a good permutation if and only if it satisfies . Find the sum of the squares of the inversion numbers of all good permutations, modulo .
The inversion number of a permutation is the number of pairs of integers such that and .
Constraints
- or .
- Each integer from to is contained at most once in .
- All input values are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
4
3 -1 2 -1
Sample Output 1
29
There are two good permutations: and , with inversion numbers and , respectively.
Thus, the answer is .
Sample Input 2
10
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
Sample Output 2
952235647
Sample Input 3
15
-1 -1 10 -1 -1 -1 2 -1 -1 3 -1 -1 -1 -1 1
Sample Output 3
460544744
Find the sum modulo .
update @ 2024/3/10 01:14:57