CF1621G.Weighted Increasing Subsequences

NOI/NOI+/CTSC

通过率:0%

时间限制:1.00s

内存限制:256MB

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 \lt i_2 \lt \ldots \lt 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} \lt a_{i_{j+1}} for each 1≤j<k1 \leq j \lt 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 1≤j≤k1 \leq j \leq k, such that exists index ik<x≤ni_k \lt x \leq n and ax>aija_x \gt 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 \gt 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.

给你一个长度为 nn 的整数序列 a1,a2,…,ana_1, a_2, \ldots, a_n。

长度为 kk 的下标序列 i1<i2<…<iki_1 \lt i_2 \lt \ldots \lt i_k 表示序列 aa 的一个长度为 kk 的子序列 ai1,ai2,…,aika_{i_1}, a_{i_2}, \ldots, a_{i_k}。

序列 aa 的一个长度为 kk 的子序列 ai1,ai2,…,aika_{i_1}, a_{i_2}, \ldots, a_{i_k} 称为递增子序列,当且仅当对每个 1≤j<k1 \leq j \lt k,均有 aij<aij+1a_{i_j} \lt a_{i_{j+1}}。

序列 aa 的一个长度为 kk 的递增子序列 ai1,ai2,…,aika_{i_1}, a_{i_2}, \ldots, a_{i_k} 的权重定义为满足如下条件的下标 jj(其中 1≤j≤k1 \leq j \leq k)的个数:存在某个下标 xx 满足 ik<x≤ni_k \lt x \leq n 且 ax>aija_x \gt a_{i_j}。

例如,若 a=[6,4,8,6,5]a = [6, 4, 8, 6, 5],则下标序列 i=[2,4]i = [2, 4] 表示 aa 的一个递增子序列 [4,6][4, 6]。该递增子序列的权重为 11,因为对 j=1j = 1,存在 x=5x = 5 使得 a5=5>ai1=4a_5 = 5 \gt a_{i_1} = 4;但对 j=2j = 2,不存在满足条件的 xx。

求序列 aa 的所有递增子序列的权重之和,并对 109+710^9+7 取模。

输入格式

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

The first line of each test case contains the single integer nn (1≤n≤2⋅1051 \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 (1≤ai≤1091 \leq a_i \leq 10^9) — the sequence aa.

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

第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000)——测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5)——序列 aa 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \leq a_i \leq 10^9)——序列 aa。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

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

对于每个测试用例,输出所有递增子序列 aa 的权重之和对 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.

在第一个测试用例中,数组 aa 的以下严格递增子序列的权重不为零:

  • [a1]=[6][a_1] = [6] 的权重为 11。
  • [a2]=[4][a_2] = [4] 的权重为 11。
  • [a2,a3]=[4,8][a_2, a_3] = [4, 8] 的权重为 11。
  • [a2,a4]=[4,6][a_2, a_4] = [4, 6] 的权重为 11。

所有严格递增子序列的权重之和为 44。

在第二个测试用例中,数组 aa 共有 77 个权重不为零的严格递增子序列:其中 33 个权重为 11,33 个权重为 22,11 个权重为 33。权重之和为 1212。

输入解题思路,AI测评打分。不知道怎么写?

首页