CF2165D.Path Split

省选/NOI-

通过率:0%

时间限制:4.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given a sequence of nn integers a1,a2,…,ana_1,a_2,\ldots,a_n.

You would like to partition aa into several subsequences∗^{\text{∗}} b1,b2,…,bkb_1,b_2,\ldots,b_k, satisfying the following conditions:

  • Each element in aa belongs to exactly one of bib_i.
  • For each sequence bib_i, let its elements be bi,1,bi,2,…,bi,pib_{i,1},b_{i,2},\ldots,b_{i,p_i}. For every 1≤j<pi1\le j \lt p_i, ∣bi,j−bi,j+1∣=1|b_{i,j}-b_{i,j+1}|=1 should hold.

Please calculate the minimum number of subsequences you can partition aa into.

∗^{\text{∗}}A sequence bib_i is a subsequence of a sequence aa if bib_i can be obtained from aa by the deletion of several (possibly, zero or all) element from arbitrary positions.

给你一个长度为 nn 的整数序列 a1,a2,…,ana_1,a_2,\ldots,a_n。

你希望将 aa 划分为若干个子序列∗^{\text{∗}} b1,b2,…,bkb_1,b_2,\ldots,b_k,满足以下条件:

  • aa 中的每个元素恰好属于某个 bib_i;
  • 对于每个子序列 bib_i,设其元素为 bi,1,bi,2,…,bi,pib_{i,1},b_{i,2},\ldots,b_{i,p_i},则对任意 1≤j<pi1\le j \lt p_i,需满足 ∣bi,j−bi,j+1∣=1|b_{i,j}-b_{i,j+1}|=1。

请计算能将 aa 划分的最小子序列个数。

∗^{\text{∗}} 序列 bib_i 是序列 aa 的一个子序列,如果 bib_i 可通过从 aa 中任意位置删除若干(可能为零个或全部)元素而得到。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤1061\le n\le10^6) — the length of the sequence aa.

The second line of each test case contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (1≤ai≤2n1\le a_i\le2n) — the sequence aa.

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1061\le n\le10^6)——序列 aa 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(1≤ai≤2n1\le a_i\le2n)——序列 aa。

保证所有测试用例的 nn 之和不超过 10610^6。

输出格式

For each test case, print a single integer on one line — the minimum number of subsequences aa can be partitioned into.

对于每个测试用例,在一行中输出一个整数——序列 aa 可被划分成的最小子序列个数。

输入输出样例

  • 输入#1

    7
    1
    1
    1
    2
    8
    11 13 10 11 11 11 13 10
    6
    8 8 6 7 7 7
    3
    5 1 3
    10
    11 14 14 13 12 14 12 10 14 12
    1
    2

    输出#1

    1
    1
    5
    3
    3
    7
    1

说明/提示

In the first test case, we can partition aa into subsequences [1][1]. It is obvious that we cannot partition aa into fewer subsequences; thus, 11 is the answer.

In the third test case, we can partition aa into subsequences [11,10,11,10],[13],[11],[11],[13][11,10,11,10],[13],[11],[11],[13]. Please note that [11,10,11,11,11,10][11,10,11,11,11,10] is not a valid sequence, since ∣11−11∣=0≠1|11-11|=0\neq1.

在第一个测试用例中,我们可以将 aa 划分为子序列 [1][1]。显然,无法将 aa 划分为更少的子序列;因此答案为 11。

在第三个测试用例中,我们可以将 aa 划分为子序列 [11,10,11,10],[13],[11],[11],[13][11,10,11,10],[13],[11],[11],[13]。请注意,[11,10,11,11,11,10][11,10,11,11,11,10] 不是一个合法的序列,因为 ∣11−11∣=0≠1|11-11|=0\neq1。

输入解题思路,AI测评打分。不知道怎么写?

首页