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

18984번 - RMQ Similar Sequence 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 256 MB33231872.000%

문제

Chiaki has a sequence $A=\{a_1,a_2,\dots,a_n\}$. Let $\mathbf{RMQ}(A, l, r)$ be the minimum $i$ ($l \le i \le r$) such that $a_i$ is the maximum value in $a_l, a_{l+1}, \dots, a_{r}$.

Two sequences $A$ and $B$ are called RMQ Similar, if they have the same length $n$ and for every 1ドル \le l \le r \le n,ドル $\mathbf{RMQ}(A, l, r) = \mathbf{RMQ}(B, l, r)$.

For a given the sequence $A=\{a_1,a_2,\dots,a_n\},ドル define the weight of a sequence $B=\{b_1,b_2,\dots,b_n\}$ be $\sum\limits_{i=1}^{n} b_i$ (i.e. the sum of all elements in $B$) if sequence $B$ and sequence $A$ are RMQ Similar, or 0ドル$ otherwise. If each element of $B$ is a real number chosen independently and uniformly at random between 0ドル$ and 1ドル,ドル find the expected weight of $B$.

입력

There are multiple test cases. The first line of input contains an integer $T,ドル indicating the number of test cases. For each test case:

The first line contains an integer $n$ (1ドル \le n \le 10^6$) -- the length of the sequence.

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ (1ドル \le a_i \le n$) denoting the sequence.

It is guaranteed that the sum of all n does not exceed 3ドル \times 10^6$.

출력

For each test case, output the answer as a value of a rational number modulo 10ドル^9 + 7$.

Formally, it is guaranteed that under given constraints the probability is always a rational number $\frac{p}{q}$ ($p$ and $q$ are integer and coprime, $q$ is positive), such that $q$ is not divisible by 10ドル^9 + 7$. Output such integer a between 0ドル$ and 10ドル^9 + 6$ that $p - aq$ is divisible by 10ドル^9 + 7$.

제한

예제 입력 1

3
3
1 2 3
3
1 2 1
5
1 2 3 2 1

예제 출력 1

250000002
500000004
125000001

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2018 > Day 4: Xi Lin Contest H번

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

출처

대학교 대회

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

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