#P14116. [IAMOI R4] 序列
[IAMOI R4] 序列
Description
Little T has two sequences, and , both of length . Some elements in sequence are determined, while the rest are undetermined. Little T must fill in the undetermined elements. All elements in sequence must be integers between and , inclusive.
After Little T determines all elements of sequence , an operation is performed times. Each operation consists of two steps:
- For all , set .
- For all , set .
Little T wants to know, after all operations are completed, what is the maximum possible number of distinct elements in sequence ?
Input Format
This problem has multiple test cases.
The first line of the input contains an integer , representing the number of test cases.
Then, test cases follow. For each test case:
- The first line contains two positive integers and , representing the length of the sequences and the number of operations.
- The second line contains integers, representing the initial sequence . If , the element at this position is undetermined. Otherwise, the element is determined.
Output Format
For each test case, output a single line containing a positive integer, which is the answer.
3
6 2
1 1 4 5 1 4
6 2
0 0 4 5 0 4
13 1
0 1 2 3 4 5 2 7 8 3 10 4 12
1
5
7
Hint
【Sample Explanation】
For the first sample case, the initial sequence is fully determined. After 2 operations, sequence becomes 1 1 1 1 1 1. The number of distinct elements is 1.
For the second sample case, Little T can set the initial sequence to 2 1 4 5 6 4. After 2 operations, sequence becomes 1 2 4 5 6 4. The number of distinct elements is 5.
【Constraints】
This problem uses bundled testing.
| Subtask | Special Property | Score | ||
|---|---|---|---|---|
| 1 | None | 10 | ||
| 2 | 15 | |||
| 3 | 10 | |||
| 4 | Yes | |||
| 5 | None | 15 | ||
| 6 | 10 | |||
| 7 | Yes | |||
| 8 | None | 20 |
- Special Property: For all , .
For all test cases, it is guaranteed that: , , , .
【Hints】
The input size may be large. Please use fast I/O methods. Please note the specific time and memory limits for this problem.
京公网安备 11011102002149号