#d11205. 最长上升子序列计数(Bonus)
最长上升子序列计数(Bonus)
Counting Longest Increasing Subsequences (Bonus)
Problem Description
This problem is a strengthened version of daimayuan problem 326; the only difference is the ranges of and .
Finding the length of the longest increasing subsequence is quite well known. Here, you are asked to compute the number of longest increasing subsequences.
Two ordered tuples are considered different if they differ in at least one value. For example, in , the subsequence using the first and the subsequence using the second count as two distinct answers.
Input Format
The input consists of two lines. The first line contains an integer , the size of the sequence .
The second line contains integers separated by spaces, representing in order.
Output Format
Output the number of longest increasing subsequences.
Since this value may be very large, output it modulo .
Sample Input 1
5
1 3 3 0 4
Sample Output 1
2
Sample Input 2
8
1 2 4 2 4 7 3 4
Sample Output 2
5
Explanation
The answers consist of: