수열 A가 주어질 때, [0,1] 위의 균등분포에서 독립적으로 뽑은 수열 B가 A와 모든 구간에서 최댓값 위치가 같을 조건 아래 B 원소 합의 기댓값을 구한다.
어려움9트리확률조합론DFS아직 제출이 없습니다시간 제한2초메모리 제한256 MBChiaki has a sequence A=a_1,a_2,…,a_n. Let RMQ(A,l,r) be the minimum i (l≤i≤r) such that a_i is the maximum value in a_l,a_l+1,…,a_r.
Two sequences A and B are called RMQ Similar, if they have the same length n and for every 1≤l≤r≤n, RMQ(A,l,r)=RMQ(B,l,r).
For a given the sequence A=a_1,a_2,…,a_n, define the weight of a sequence B=b_1,b_2,…,b_n be ∑_i=1nb_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≤n≤106) -- the length of the sequence.
The second line contains n integers a_1,a_2,…,a_n (1≤a_i≤n) denoting the sequence.
It is guaranteed that the sum of all n does not exceed 3×106.
For each test case, output the answer as a value of a rational number modulo 109+7.
Formally, it is guaranteed that under given constraints the probability is always a rational number qp (p and q are integer and coprime, q is positive), such that q is not divisible by 109+7. Output such integer a between 0 and 109+6 that p−aq is divisible by 109+7.