Number of Longest Increasing Subsequences
InterviewTime limit1sMemory limit128 MB
Count how many strictly increasing subsequences of the given sequence attain the maximum possible length, modulo m.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Segment tree
- Solved
- No attempts yet
Problem
Compute the number of longest strictly increasing subsequences of a sequence , modulo .
A subsequence is obtained from by deleting zero or more elements while keeping the relative order of the remaining ones. A strictly increasing subsequence is one in which every element is strictly greater than the element before it. Among all strictly increasing subsequences, the longest ones are those of maximum length; there may be several of them, and you must count how many there are. Two subsequences are considered different when they use different sets of positions of .
Input
The first line contains the length of the sequence and the modulus (, ).
The second line contains the elements of , separated by spaces ().
Output
Print a single line containing the number of longest strictly increasing subsequences of , taken modulo .