题库练习 On Sum of Number of Inversions in Permutations
← 上一题 下一题 →

A9462 | On Sum of Number of Inversions in Permutations

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

You are given a permutation $p$ . Calculate the total number of inversions in all permutations that lexicographically do not exceed the given one.

As this number can be very large, print it modulo $1000000007$ $(10^{9}+7)$ .

输入格式

The first line contains a single integer $n$ ( $1<=n<=10^{6}$ ) — the length of the permutation. The second line contains $n$ distinct integers $p_{1},p_{2},...,p_{n}$ ( $1<=p_{i}<=n$ ).

输出格式

Print a single number — the answer to the problem modulo $1000000007$ $(10^{9}+7)$ .

输入输出样例

输入 #1
2
2 1
输出 #1
1
输入 #2
3
2 1 3
输出 #2
2
C++ 编辑器
输入
输出