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:||ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 6.3, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYPY, PYTH, PYTH 3.5, RUBY, SCALA, SCM chicken, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC|
Fetching successful submissions
If you are still having problems, see a sample solution here.