Logo
(追記) (追記ここまで)

23138번 - Swapping Inversions 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 256 MB26171666.667%

문제

You are given a permutation $x$ of the integers from 1ドル$ to $n$.

You want to sort this permutation by a sequence of operations. In one operation, you select two adjacent elements $x_i$ and $x_{i+1}$ such that $x_i > x_{i+1}$ and swap them. When there are multiple choices of such $i,ドル you choose one of them with equal probability. When there is no such $i,ドル the process ends.

The cost of swapping $x_i$ and $x_{i+1}$ is $|x_i - x_{i+1}|$. Calculate the expected total cost of sorting the permutation modulo 10ドル^9 + 7$.

입력

The first line of input contains an integer $n$ (1ドル \leq n \leq 10^6$).

The second line contains $n$ integers $x_1, x_2, \ldots, x_n$ (1ドル \leq x_i \leq n$). It is guaranteed that $x$ is a permutation of the integers from 1ドル$ to $n$.

출력

Print a single line containing an integer: the expected total cost modulo 10ドル^9 + 7$.

Formally, it can be shown that the expected total cost can be represented as a fraction $p / q$ for some coprime non-negative integers $p$ and $q$. For example, if the expected total cost is an integer, then we just have $q = 1$. You have to print the value $p \cdot q^{-1} \bmod (10^9 + 7)$.

제한

예제 입력 1

5
1 2 3 4 5

예제 출력 1

0

예제 입력 2

5
1 2 5 3 4

예제 출력 2

3

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2021 > Day 5: 2021 Shanghai ICPC Camp Onsite 2 by PKU A번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /