#P6885. [COCI 2016/2017 #3] Zoltan

    ID: 7306 远端评测题 1000ms 32MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP2016树状数组COCI(克罗地亚)

[COCI 2016/2017 #3] Zoltan

Problem Description

Marton’s friend Cero has an array of NN positive integers.

First, Cero writes the first number of this array on the blackboard. Then, each time he writes the next number either to the left or to the right of all the numbers already written. Repeating this operation produces a sequence.

Note that two sequences constructed in this way are considered the same if and only if the writing order and the side chosen for every number are exactly the same. For example, 1,11,1 may be different from 1,11,1: in the former, the second number is written to the left of the first one, while in the latter, the second number is written to the right of the first one.

Among all sequences that can be formed, let MM be the maximum possible length of the longest strictly increasing subsequence. Also, among all sequences whose longest strictly increasing subsequence length equals MM, compute the sum of the numbers of longest strictly increasing subsequences. Since the answer may be very large, output this value modulo 109+710^9+7.

Input Format

The first line contains a positive integer NN.

The next line contains NN positive integers, the elements of the array given in order.

Output Format

Output one line containing the maximum length MM and the required total count modulo 109+710^9+7.

2
1 1 
1 4 
4
2 1 3 4 
4 1

Hint

Sample Explanation

Sample 1 Explanation

Cero can construct 22 different sequences: 1,11,1 and 1,11,1.

Clearly, the length of the longest strictly increasing subsequence is 11, and there are 44 subsequences that satisfy this.

Sample 2 Explanation

The length of the longest strictly increasing subsequence is 44, and only 1,2,3,41,2,3,4 satisfies this.

Constraints

For 30%30\% of the testdata, N20N \le 20.

For 50%50\% of the testdata, N103N \le 10^3.

For 100%100\% of the testdata, N2×105N \le 2 \times 10^5, and each element in the array is 109\le 10^9.

Note

Translated from COCI2016-2017 CONTEST #3 T5 Zoltan.

The explanations for Samples 1 and 2 are unofficial.

Translated by ChatGPT 5