CF1621G.Weighted Increasing Subsequences
NOI/NOI+/CTSC
通过率:0%
时间限制:1.00s
内存限制:256MB
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.
给你一个长度为 n 的整数序列 a1,a2,…,an。
长度为 k 的下标序列 i1<i2<…<ik 表示序列 a 的一个长度为 k 的子序列 ai1,ai2,…,aik。
序列 a 的一个长度为 k 的子序列 ai1,ai2,…,aik 称为递增子序列,当且仅当对每个 1≤j<k,均有 aij<aij+1。
序列 a 的一个长度为 k 的递增子序列 ai1,ai2,…,aik 的权重定义为满足如下条件的下标 j(其中 1≤j≤k)的个数:存在某个下标 x 满足 ik<x≤n 且 ax>aij。
例如,若 a=[6,4,8,6,5],则下标序列 i=[2,4] 表示 a 的一个递增子序列 [4,6]。该递增子序列的权重为 1,因为对 j=1,存在 x=5 使得 a5=5>ai1=4;但对 j=2,不存在满足条件的 x。
求序列 a 的所有递增子序列的权重之和,并对 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.
第一行包含一个整数 t(1≤t≤1000)——测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)——序列 a 的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)——序列 a。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, print the sum of weights of all increasing subsequences a modulo 109+7.
对于每个测试用例,输出所有递增子序列 a 的权重之和对 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.
在第一个测试用例中,数组 a 的以下严格递增子序列的权重不为零:
- [a1]=[6] 的权重为 1。
- [a2]=[4] 的权重为 1。
- [a2,a3]=[4,8] 的权重为 1。
- [a2,a4]=[4,6] 的权重为 1。
所有严格递增子序列的权重之和为 4。
在第二个测试用例中,数组 a 共有 7 个权重不为零的严格递增子序列:其中 3 个权重为 1,3 个权重为 2,1 个权重为 3。权重之和为 12。
输入解题思路,AI测评打分。不知道怎么写?