CF1870G.MEXanization

普及/提高-

通过率:0%

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.

输入格式

The first line contains a single integer tt ( 1t1041 \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 ( 1n21051 \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 ( 0ai21050 \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 21052 \cdot 10^5 .

输出格式

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

输入输出样例

  • 输入#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.

首页