CF2165D.Path Split
省选/NOI-
通过率:0%
时间限制:4.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a sequence of n integers a1,a2,…,an.
You would like to partition a into several subsequences∗ b1,b2,…,bk, satisfying the following conditions:
- Each element in a belongs to exactly one of bi.
- For each sequence bi, let its elements be bi,1,bi,2,…,bi,pi. For every 1≤j<pi, ∣bi,j−bi,j+1∣=1 should hold.
Please calculate the minimum number of subsequences you can partition a into.
∗A sequence bi is a subsequence of a sequence a if bi can be obtained from a by the deletion of several (possibly, zero or all) element from arbitrary positions.
给你一个长度为 n 的整数序列 a1,a2,…,an。
你希望将 a 划分为若干个子序列∗ b1,b2,…,bk,满足以下条件:
- a 中的每个元素恰好属于某个 bi;
- 对于每个子序列 bi,设其元素为 bi,1,bi,2,…,bi,pi,则对任意 1≤j<pi,需满足 ∣bi,j−bi,j+1∣=1。
请计算能将 a 划分的最小子序列个数。
∗ 序列 bi 是序列 a 的一个子序列,如果 bi 可通过从 a 中任意位置删除若干(可能为零个或全部)元素而得到。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains a single integer n (1≤n≤106) — the length of the sequence a.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤2n) — the sequence a.
It is guaranteed that the sum of n over all test cases does not exceed 106.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤106)——序列 a 的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤2n)——序列 a。
保证所有测试用例的 n 之和不超过 106。
输出格式
For each test case, print a single integer on one line — the minimum number of subsequences a can be partitioned into.
对于每个测试用例,在一行中输出一个整数——序列 a 可被划分成的最小子序列个数。
输入输出样例
输入#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 a into subsequences [1]. It is obvious that we cannot partition a into fewer subsequences; thus, 1 is the answer.
In the third test case, we can partition a into subsequences [11,10,11,10],[13],[11],[11],[13]. Please note that [11,10,11,11,11,10] is not a valid sequence, since ∣11−11∣=0=1.
在第一个测试用例中,我们可以将 a 划分为子序列 [1]。显然,无法将 a 划分为更少的子序列;因此答案为 1。
在第三个测试用例中,我们可以将 a 划分为子序列 [11,10,11,10],[13],[11],[11],[13]。请注意,[11,10,11,11,11,10] 不是一个合法的序列,因为 ∣11−11∣=0=1。
输入解题思路,AI测评打分。不知道怎么写?