Repovive
  • Dashboard
  • Ranking
  • Submissions
  • Discussion
  1. Contests
  2. Premier Round 3
  3. 6E

My submissions

/
/
/
/

Announcements

My submissions

/
/
/
/

Announcements

Solve
Author

6E. Mex Extension

2500 pts·2s·256 MB

Constraints

Input

Output

Samples

Input
t
5
Case 1
1 1
0
Case 2
4 1
1 0 3 2
Case 3
5 2
0 2 1 0 4
Case 4
6 3
3 3 0 1 2 6
Case 5
7 4
1 2 0 4 3 6 5
Explanation
Case 1
Case 2
Case 3
Case 4
Case 5
Output
Case 1
2
Case 2
2 3 4 5
Case 3
2 4 4 5 6
Case 4
1 2 4 4 5 7
Case 5
2 4 5 6 7 8 9

We define the score of an array b1,b2,…,bmb_1,b_2,\ldots,b_mb1​,b2​,…,bm​ as follows.

Start with an empty set SSS.

For each iii from 111 to mmm:

  1. Insert bib_ibi​ into SSS.
  2. After that, you may insert mex⁡(S)\operatorname{mex}(S)mex(S) into SSS.

The second step can be used at most kkk times in total. Here mex⁡(S)\operatorname{mex}(S)mex(S) is the smallest non-negative integer that does not belong to SSS.

The score of the array is the maximum possible value of mex⁡(S)\operatorname{mex}(S)mex(S) after all elements are processed.

You are given an array a1,a2,…,ana_1,a_2,\ldots,a_na1​,a2​,…,an​. For each rrr with 1≤r≤n1 \le r \le n1≤r≤n, output the score of the prefix a1,a2,…,ara_1,a_2,\ldots,a_ra1​,a2​,…,ar​.

  • 1≤t≤1041 \le t \le 10^41≤t≤104
  • 1≤n≤2×1051 \le n \le 2 \times 10^51≤n≤2×105
  • 1≤k≤n1 \le k \le n1≤k≤n
  • 0≤ai≤n0 \le a_i \le n0≤ai​≤n
  • The sum of nnn over all test cases is at most 2×1052 \times 10^52×105
ttt nka1a2⋯an}×t\left. \begin{array}{l} n \quad k \\ a_1 \quad a_2 \quad \cdots \quad a_n \end{array} \right\} \times tnka1​a2​⋯an​​}×t
f(1)f(2)⋯f(n)}×t\left. \begin{array}{l} f(1) \quad f(2) \quad \cdots \quad f(n) \end{array} \right\} \times tf(1)f(2)⋯f(n)​}×t

Here f(r)f(r)f(r) is the score of the prefix a1,a2,…,ara_1,a_2,\ldots,a_ra1​,a2​,…,ar​.

For the only prefix, we start with an empty set.

First, we insert 000, so S={0}S=\{0\}S={0}. Then we use the operation and insert mex⁡(S)=1\operatorname{mex}(S)=1mex(S)=1. Now S={0,1}S=\{0,1\}S={0,1}, so the final mex is 222.

For the prefix [1][1][1], after inserting 111, we use the operation and insert 000. The final set contains 000 and 111, so the score is 222.

For the prefix [1,0][1,0][1,0], first insert 111, then use the operation to insert 000. After that, the array also inserts 000. The final set contains 000 and 111, so the score is 222.

For the prefix [1,0,3][1,0,3][1,0,3], first insert 111, then insert 000. After that, use the operation and insert 222. Finally, insert 333. The final set contains 0,1,2,30,1,2,30,1,2,3, so the score is 444.

For the prefix [1,0,3,2][1,0,3,2][1,0,3,2], the same operation after inserting 000 gives 222. The final set contains 0,1,2,30,1,2,30,1,2,3, so the score is 444.

For the full prefix [0,2,1,0,4][0,2,1,0,4][0,2,1,0,4], use the first operation after inserting 000 to insert 111. Then insert 222 from the array. Use the second operation to insert 333. Finally, the array inserts 444. The final set contains 0,1,2,3,40,1,2,3,40,1,2,3,4, so the score is 555.

For the prefix [3,3,0][3,3,0][3,3,0], after inserting the first 333, use one operation to insert 000. After inserting the second 333, use another operation to insert 111. After inserting 000, use the last operation to insert 222. The final set contains 0,1,2,30,1,2,30,1,2,3, so the score is 444.

For the full prefix [1,2,0,4,3,6,5][1,2,0,4,3,6,5][1,2,0,4,3,6,5], use the operations after inserting the 3rd, 4th, 6th, and 7th elements.

After inserting 000, the set contains 0,1,20,1,20,1,2, so the operation inserts 333.

After inserting 444, the operation inserts 555.

After inserting 666, the operation inserts 777.

After inserting 555, the operation inserts 888.

So the final set contains all numbers from 000 to 888, and the score is 999.