CF1870G.MEXanization

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Let's define f(S)f(S). Let SS be a multiset (i.e., it can contain repeated elements) of non-negative integers. In one operation, you can choose any non-empty subset of SS (which can also contain repeated elements), remove this subset (all elements in it) from SS, and add the MEX of the removed subset to SS. You can perform any number of such operations. After all the operations, SS should contain exactly 11 number. f(S)f(S) is the largest number that could remain in SS after any sequence of operations.

You are given an array of non-negative integers aa of length nn. For each of its nn prefixes, calculate f(S)f(S) if SS is the corresponding prefix (for the ii-th prefix, SS consists of the first ii elements of array aa).

The MEX (minimum excluded) of an array is the smallest non-negative integer that does not belong to the array. For instance:

  • The MEX of [2,2,1][2,2,1] is 00, because 00 does not belong to the array.
  • The MEX of [3,1,0,1][3,1,0,1] is 22, because 00 and 11 belong to the array, but 22 does not.
  • The MEX of [0,3,1,2][0,3,1,2] is 44, because 00, 11, 22 and 33 belong to the array, but 44 does not.

我们定义函数 f(S)f(S)。设 SS 是一个非负整数的多重集(即,其中可以包含重复元素)。一次操作定义为:任选 SS 的一个非空子集(该子集也可以包含重复元素),将该子集中的所有元素从 SS 中移除,并将该子集的 MEX 值加入 SS。你可以执行任意多次此类操作。所有操作结束后,SS 中必须恰好剩下 11 个数。f(S)f(S) 表示在所有可能的操作序列下,最终 SS 中所能剩下的最大数值。

给定一个长度为 nn 的非负整数数组 aa。对它的每个长度为 ii 的前缀(i=1,2,…,ni = 1, 2, \dots, n),计算 f(S)f(S) 的值,其中 SS 即为该前缀(即第 ii 个前缀对应 SS 由数组 aa 的前 ii 个元素构成)。

数组的 MEX(最小未出现值)是指不属于该数组的最小非负整数。例如:

  • [2,2,1][2,2,1] 的 MEX 是 00,因为 00 不在数组中。
  • [3,1,0,1][3,1,0,1] 的 MEX 是 22,因为 00 和 11 在数组中,但 22 不在。
  • [0,3,1,2][0,3,1,2] 的 MEX 是 44,因为 00、11、22 和 33 都在数组中,但 44 不在。

输入格式

The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases. Then follows the description of the test cases.

The first line of each test case contains an integer nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5) — the size of array aa.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤2⋅1050 \leq a_i \leq 2 \cdot 10^5) — the array aa.

It is guaranteed that the sum of all nn values across all test cases does not exceed 2⋅1052 \cdot 10^5.

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

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5)—— 数组 aa 的大小。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤2⋅1050 \leq a_i \leq 2 \cdot 10^5)—— 数组 aa。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output nn numbers: f(S)f(S) for each of the nn prefixes of array aa.

对于每个测试用例,输出 nn 个数:数组 aa 的每个长度为 1,2,…,n1,2,\dots,n 的前缀 SS 对应的 f(S)f(S) 值。

输入输出样例

  • 输入#1

    4
    8
    179 57 2 0 2 3 2 3
    1
    0
    3
    1 0 3
    8
    1 0 1 2 4 3 0 2

    输出#1

    179 2 3 3 3 4 4 5 
    1 
    1 2 2 
    1 2 2 3 3 5 5 5

说明/提示

Consider the first test case. For a prefix of length 11, the initial multiset is 179{179}. If we do nothing, we get 179179.

For a prefix of length 22, the initial multiset is 57,179{57, 179}. Using the following sequence of operations, we can obtain 22.

  1. Apply the operation to 57{57}, the multiset becomes 0,179{0, 179}.
  2. Apply the operation to 179{179}, the multiset becomes 0,0{0, 0}.
  3. Apply the operation to 0{0}, the multiset becomes 0,1{0, 1}.
  4. Apply the operation to 0,1{0, 1}, the multiset becomes 2{2}. This is our answer.

Consider the second test case. For a prefix of length 11, the initial multiset is 0{0}. If we apply the operation to 0{0}, the multiset becomes 1{1}. This is the answer.

考虑第一个测试用例。对于长度为 11 的前缀,初始多重集为 179{179}。若不进行任何操作,结果为 179179。

对于长度为 22 的前缀,初始多重集为 57,179{57, 179}。通过以下操作序列,我们可以得到 22:

  1. 对 57{57} 应用操作,多重集变为 0,179{0, 179}。
  2. 对 179{179} 应用操作,多重集变为 0,0{0, 0}。
  3. 对 0{0} 应用操作,多重集变为 0,1{0, 1}。
  4. 对 0,1{0, 1} 应用操作,多重集变为 2{2}。此即所求答案。

考虑第二个测试用例。对于长度为 11 的前缀,初始多重集为 0{0}。若对 0{0} 应用操作,多重集变为 1{1}。此即所求答案。

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

首页