CF1881E.Block Sequence

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Given a sequence of integers aa of length nn .

A sequence is called beautiful if it has the form of a series of blocks, each starting with its length, i.e., first comes the length of the block, and then its elements. For example, the sequences [ 3, 3, 4, 5, 2, 6, 1\color{red}{3},\ \color{red}{3},\ \color{red}{4},\ \color{red}{5},\ \color{green}{2},\ \color{green}{6},\ \color{green}{1} ] and [ 1, 8, 4, 5, 2, 6, 1\color{red}{1},\ \color{red}{8},\ \color{green}{4},\ \color{green}{5},\ \color{green}{2},\ \color{green}{6},\ \color{green}{1} ] are beautiful (different blocks are colored differently), while [ 11 ], [ 1, 4, 31,\ 4,\ 3 ], [ 3, 2, 13,\ 2,\ 1 ] are not.

In one operation, you can remove any element from the sequence. What is the minimum number of operations required to make the given sequence beautiful?

输入格式

The first line of the input contains a single integer tt ( 1t1041 \le t \le 10^4 ) — the number of test cases. Then follows the descriptions of the test cases.

The first line of each test case contains a single integer nn ( 1n21051 \le n \le 2 \cdot 10^5 ) — the length of the sequence aa .

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 1ai1061 \le a_i \le 10^6 ) — the elements of the sequence aa .

It is guaranteed that the sum of the values of nn over all test cases does not exceed 21052 \cdot 10^5 .

输出格式

For each test case, output a single number — the minimum number of deletions required to make the sequence aa beautiful.

输入输出样例

  • 输入#1

    7
    7
    3 3 4 5 2 6 1
    4
    5 6 3 2
    6
    3 4 1 6 7 7
    3
    1 4 3
    5
    1 2 3 4 5
    5
    1 2 3 1 2
    5
    4 5 5 1 5

    输出#1

    0
    4
    1
    1
    2
    1
    0

说明/提示

In the first test case of the example, the given sequence is already beautiful, as shown in the statement.

In the second test case of the example, the sequence can only be made beautiful by removing all elements from it.

In the fifth test case of the example, the sequence can be made beautiful by removing the first and last elements. Then the sequence will become [ 2, 3, 42,\ 3,\ 4 ].

首页