#P9171. [省选联考 2023] 染色数组
[省选联考 2023] 染色数组
Problem Description
Given a positive integer array of length , where each number is between and , arranged from left to right. Now we want to color each number either red or green. We call a coloring scheme an excellent coloring scheme if and only if it satisfies:
- Each number is colored either red or green.
- The red numbers are strictly increasing from left to right, and the green numbers are strictly decreasing from left to right.
For example, in , coloring red and green is an excellent coloring scheme ($\color{red}1\color{green}9\color{red}347\color{green}6$). Coloring red and green is also an excellent coloring scheme ($\color{red}1\color{green}9\color{red}34\color{green}7\color{red}6$). However, coloring red and green is not an excellent coloring scheme, because is not increasing. In , coloring and either one of the 's red, and coloring and the other green, is also an excellent coloring scheme (one possible scheme is ).
If an array has at least two different excellent coloring schemes, then this array is called perfect. (Two coloring schemes are different if and only if there exists at least one position where the number is colored differently.)
For example, and are both perfect, because excellent coloring schemes have already been given for each above. But is not perfect, because no excellent coloring scheme exists. Also, is not perfect, because there is only one excellent coloring scheme ($\color{red}1\color{green}5\color{red}36\color{green}4$).
Additional note: If there are only or red numbers, we also consider them strictly increasing; similarly, if there are only or green numbers, we also consider them strictly decreasing. For example, and are both excellent coloring schemes, so is a perfect array.
We define a way to score a coloring scheme.
For each ordered pair of elements :
- If is colored red and , then this pair scores points.
- If is colored green and , then this pair scores points.
- If neither 1 nor 2 is satisfied, then this pair scores points.
Then the score of a coloring scheme is the sum of scores over all ordered pairs.
The score of a perfect array is the maximum score among all its excellent coloring schemes.
Now the first numbers of array are fixed. You need to answer the following two questions:
- Question 1: How many ways are there to determine the remaining numbers of such that is a perfect array?
- Question 2: What is the sum of the scores of all possible perfect arrays?
Since the answer can be very large, you only need to output the result modulo .
Input Format
This problem contains multiple test cases.
The first line of input contains a positive integer , denoting the number of test cases.
Then there are test cases. Each test case is formatted as follows:
The first line contains three integers , denoting the array length, the maximum value in the array, and the length of the fixed prefix.
The second line contains positive integers , denoting the fixed prefix.
Output Format
For each test case, output one line containing two integers separated by a single space.
-
The first integer is the number of perfect arrays modulo .
-
The second integer is the sum of scores of all perfect arrays modulo .
5
6 10 6
1 9 3 4 7 6
5 8 4
1 7 2 6
9 10 2
3 6
6 11 6
1 7 5 8 3 9
9 10 5
5 10 6 4 7
1 63
8 245
29378 1267731
1 17
78 1820
见附件中的 color/color2.in
见附件中的 color/color2.ans
Hint
【Scoring】
Each test point is worth points.
Each line should output the answers to the two questions in order. Any output that does not match the required format will get points.
If your program answers only Question 1 correctly, you get point. If it answers only Question 2 correctly, you get points. If it answers both correctly, you get points.
If you do not answer Question 1 or Question 2, you still need to output any integer in the corresponding position to satisfy the output format.
【Subtasks】
For all testdata, it is guaranteed that: ; ; ; ; .

Translated by ChatGPT 5