CF1621G.Weighted Increasing Subsequences

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given the sequence of integers a1,a2,,ana_1, a_2, \ldots, a_n of length nn .

The sequence of indices i1<i2<<iki_1 < i_2 < \ldots < i_k of length kk denotes the subsequence ai1,ai2,,aika_{i_1}, a_{i_2}, \ldots, a_{i_k} of length kk of sequence aa .

The subsequence ai1,ai2,,aika_{i_1}, a_{i_2}, \ldots, a_{i_k} of length kk of sequence aa is called increasing subsequence if aij<aij+1a_{i_j} < a_{i_{j+1}} for each 1j<k1 \leq j < k .

The weight of the increasing subsequence ai1,ai2,,aika_{i_1}, a_{i_2}, \ldots, a_{i_k} of length kk of sequence aa is the number of 1jk1 \leq j \leq k , such that exists index ik<xni_k < x \leq n and ax>aija_x > a_{i_j} .

For example, if a=[6,4,8,6,5]a = [6, 4, 8, 6, 5] , then the sequence of indices i=[2,4]i = [2, 4] denotes increasing subsequence [4,6][4, 6] of sequence aa . The weight of this increasing subsequence is 11 , because for j=1j = 1 exists x=5x = 5 and a5=5>ai1=4a_5 = 5 > a_{i_1} = 4 , but for j=2j = 2 such xx doesn't exist.

Find the sum of weights of all increasing subsequences of aa modulo 109+710^9+7 .

输入格式

The first line contains a single integer tt ( 1t10001 \leq t \leq 1000 ) — the number of test cases.

The first line of each test case contains the single integer nn ( 1n21051 \leq n \leq 2 \cdot 10^5 ) — the length of the sequence aa .

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 1ai1091 \leq a_i \leq 10^9 ) — the sequence aa .

It is guaranteed that the sum of nn over all test cases doesn't exceed 21052 \cdot 10^5 .

输出格式

For each test case, print the sum of weights of all increasing subsequences aa modulo 109+710^9+7 .

输入输出样例

  • 输入#1

    4
    5
    6 4 8 6 5
    4
    1 2 3 4
    3
    3 2 2
    4
    4 5 6 5

    输出#1

    4
    12
    0
    6

说明/提示

In the first test case the following increasing subsequences of aa have not zero weight:

  • The weight of [a1]=[6][a_1] = [6] is 11 .
  • The weight of [a2]=[4][a_2] = [4] is 11 .
  • The weight of [a2,a3]=[4,8][a_2, a_3] = [4, 8] is 11 .
  • The weight of [a2,a4]=[4,6][a_2, a_4] = [4, 6] is 11 .

The sum of weights of increasing subsequences is 44 .In the second test case there are 77 increasing subsequences of aa with not zero weight: 33 with weight 11 , 33 with weight 22 and 11 with weight 33 . The sum of weights is 1212 .

首页