#P15866. 【MX-X26-T2】「Cfz Round 7」Tap Tap Dance

【MX-X26-T2】「Cfz Round 7」Tap Tap Dance

Background

The direction indicated by the compass, / the direction the compass points to.

What the heart desires, / is where the heart is heading.

Problem Description

Yuki has a sequence aa of length nn.

Yuki defines one "Yuyu" operation as:

  • Choose two integers l,rl, r such that 1≤l≤r≤n1 \le l \le r \le n.
  • Let the mex⁡\operatorname{mex} of al∼ara_l \sim a_r be xx. Delete the numbers in al∼ara_l \sim a_r that are greater than xx, and set nn to be the length of the sequence aa after this.

You need to find the minimum number of "Yuyu" operations needed to make the sequence aa as short as possible.

In this problem, the mex⁡\operatorname{mex} of a sequence is the smallest non-negative integer that does not appear in the sequence. For example:

  • mex⁡({1,2,3})=0\operatorname{mex}(\{1,2,3\}) = 0.
  • mex⁡({0})=1\operatorname{mex}(\{0\}) = 1.
  • mex⁡({1,0,2,4})=3\operatorname{mex}(\{1,0,2,4\}) = 3.

In particular, when the sequence is empty, its mex⁡\operatorname{mex} is 00.

Input Format

This problem has multiple test cases.

The first line of the input contains two integers c,tc, t, which represent the subtask number of this test point and the number of test cases. The sample satisfies c=0c = 0.

Then the test cases follow one by one. For each test case:

  • The first line contains an integer nn.
  • The second line contains nn integers a1,…,ana_1, \dots, a_n.

Output Format

For each test case, output one line containing one integer, which is the minimum number of "Yuyu" operations needed to make the sequence aa as short as possible.

0 5
4
2 0 2 6
5
1 0 3 3 1
5
1 1 8 3 1
6
1 0 3 1 0 2
7
4 0 9 8 1 3 8
1
2
1
3
2

Hint

Sample 1 Explanation

For the 11st test case, you can directly choose l=1l = 1 and r=nr = n to perform a "Yuyu" operation, which makes the sequence aa become {0}\{0\}. It is easy to prove that 00 cannot be deleted, so the length of aa is minimized at this point.

For the 22nd test case, you can first choose l=1l = 1 and r=1r = 1 to perform a "Yuyu" operation, and the sequence aa becomes {0,3,3,1}\{0,3,3,1\}. Then choose l=2l = 2 and r=4r = 4 to perform a "Yuyu" operation, and the sequence aa becomes {0}\{0\}, reaching the minimum length.

Constraints

Let ∑n\sum n denote the sum of nn within a single test point.

For all test cases:

  • 1≤t≤1051 \le t \le 10^5.
  • 1≤n≤5⋅1051 \le n \le 5 \cdot 10^5, ∑n≤5⋅105\sum n \le 5 \cdot 10^5.
  • For all 1≤i≤n1 \le i \le n, 0≤ai≤1090 \le a_i \le 10^9.

This problem uses bundled tests.

  • Subtask 1 (18 points): n≤10n \le 10, ∑n≤10\sum n \le 10.
  • Subtask 2 (5 points): It is guaranteed that there is no 00 in the sequence aa.
  • Subtask 3 (21 points): It is guaranteed that there is exactly one 00 in the sequence aa.
  • Subtask 4 (24 points): For all positive odd numbers ii not greater than nn, it is guaranteed that ai=0a_i = 0.
  • Subtask 5 (32 points): No special constraints.

Translated by ChatGPT 5