#P9970. [THUPC 2024 初赛] 套娃

[THUPC 2024 初赛] 套娃

Problem Description

We define the mex\operatorname{mex} of a set SS as the smallest non-negative integer that is not in SS.

Given a sequence a1,,ana_1,\dots,a_n, for each 1kn1\leq k\leq n, we define bkb_k in the following way:

  • For all subarrays of aa with length kk, compute the mex\operatorname{mex} of the set of numbers in that subarray.
  • For the set of all computed mex\operatorname{mex} values, compute the mex\operatorname{mex} of this set, and denote it as bkb_k.

You are asked to output the sequence bb.

Input Format

The first line contains a positive integer nn (1n1051\leq n\leq 10^5).

The second line contains nn integers a1,,ana_1,\dots,a_n (0ain0\leq a_i\leq n).

Output Format

Output nn integers b1,,bnb_1,\dots,b_n in one line.

6
0 0 0 1 2 3

2 3 4 0 0 0

Hint

Problem Usage Agreement

From the THUPC2024 (Tsinghua University Student Programming Contest and Collegiate Invitational Contest 2024) preliminary round.

The following "this repository" all refer to the THUPC2024 preliminary round official repository (https://github.com/ckw20/thupc2024_pre_public).

  1. Any organization or individual may use or repost the problems in this repository for free.

  2. When using the problems in this repository, any organization or individual should do so for free and publicly. It is strictly forbidden to use these problems for profit or to add special access permissions to these problems.

  3. If possible, when using the problems in this repository, please also provide ways to obtain resources such as testdata, reference solutions, and editorials. Otherwise, please attach the GitHub link of this repository.

Translated by ChatGPT 5