Sum of LIS lengths over every consecutive subsequence
Time limit1sMemory limit128 MB
Sum the LIS lengths of all contiguous subarrays for each test case of distinct integers.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Binary search, Brute force
- Solved
- No attempts yet
Problem
Mr. C is interested in the longest increasing subsequence problem. A sequence is given. A subsequence of is increasing when , and the longest increasing subsequence of is its LIS.
A consecutive subsequence of is a subsequence whose elements are adjacent in the original sequence. Find the LIS length of every consecutive subsequence of non-zero length, then add all of those lengths together.
Input
The first line contains an integer , the number of cases. It is followed by blocks, each one case.
The first line of each case contains an integer (), the length of .
The next lines each contain an integer (), the -th element of . Every element of is distinct.
Output
Print lines, one per case, in the same order as the input.
The -th line has the format Case #i: X, where is the case number and is the total LIS length over every consecutive subsequence of non-zero length in that case.