CF1621G.Weighted Increasing Subsequences
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given the sequence of integers a1,a2,…,an of length n .
The sequence of indices i1<i2<…<ik of length k denotes the subsequence ai1,ai2,…,aik of length k of sequence a .
The subsequence ai1,ai2,…,aik of length k of sequence a is called increasing subsequence if aij<aij+1 for each 1≤j<k .
The weight of the increasing subsequence ai1,ai2,…,aik of length k of sequence a is the number of 1≤j≤k , such that exists index ik<x≤n and ax>aij .
For example, if a=[6,4,8,6,5] , then the sequence of indices i=[2,4] denotes increasing subsequence [4,6] of sequence a . The weight of this increasing subsequence is 1 , because for j=1 exists x=5 and a5=5>ai1=4 , but for j=2 such x doesn't exist.
Find the sum of weights of all increasing subsequences of a modulo 109+7 .
输入格式
The first line contains a single integer t ( 1≤t≤1000 ) — the number of test cases.
The first line of each test case contains the single integer n ( 1≤n≤2⋅105 ) — the length of the sequence a .
The second line of each test case contains n integers a1,a2,…,an ( 1≤ai≤109 ) — the sequence a .
It is guaranteed that the sum of n over all test cases doesn't exceed 2⋅105 .
输出格式
For each test case, print the sum of weights of all increasing subsequences a modulo 109+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 a have not zero weight:
- The weight of [a1]=[6] is 1 .
- The weight of [a2]=[4] is 1 .
- The weight of [a2,a3]=[4,8] is 1 .
- The weight of [a2,a4]=[4,6] is 1 .
The sum of weights of increasing subsequences is 4 .In the second test case there are 7 increasing subsequences of a with not zero weight: 3 with weight 1 , 3 with weight 2 and 1 with weight 3 . The sum of weights is 12 .