All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian as well.
Given a sequence of n numbers A[1..n], a length-k increasing subsequence (IS) is A[i1], A[i2], ..., A[ik] such that both the indices i and values are strictly increasing. Among all possible IS's, denote the maximum length as L. Now we are interested in finding how many length-(L-1) IS's are there.
Two IS's are different if and only if their indices are different.
Since the answer could be very large, you are just required to output its remainder with 10^9 + 7.
The first line contains an integer T denoting the total number of test cases.
For each test case, the first line contains a single integer n, and the second line contains the space-separated sequence A[1..n].
For each test case, output the answer per line.
- 1 <= T <= 10
- 1 <= n <= 10^5
- 1 <= A[i] <= 10^9
- 1 < L
Input: 3 3 1 1 2 5 6 8 1 2 3 5 2 3 1 6 8 Output: 3 4 5
Example case 1. L = 2. There are 3 different length-1 IS's.
|Tags||cook63, medium, segment-tree, shangjingbo|
|Time Limit:||3 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.