#P11837. [USACO25FEB] Making Mexes B

[USACO25FEB] Making Mexes B

Description

You are given an array aa of NN non-negative integers a1,a2,,aNa_1, a_2, \dots, a_N (1N2105,0aiN1\le N\le 2\cdot 10^5, 0\le a_i\le N). In one operation, you can change any element of aa to any non-negative integer.

The mex of an array is the minimum non-negative integer that it does not contain. For each ii in the range 00 to NN inclusive, compute the minimum number of operations you need in order to make the mex of aa equal ii.

Input Format

The first line contains NN.

The next line contains a1,a2,,aNa_1,a_2,\dots, a_N.

Output Format

For each ii in the range 00 to NN, output the minimum number of operations for ii on a new line. Note that it is always possible to make the mex of aa equal to any ii in the range 00 to NN.

4
2 2 2 0
1
0
3
1
2

Hint

For Sample 1:
  • To make the mex of aa equal to 00, we can change a4a_4 to 33 (or any positive integer). In the resulting array, [2,2,2,3][2, 2, 2, 3], 00 is the smallest non-negative integer that the array does not contain, so 00 is the mex of the array.
  • To make the mex of aa equal to 11, we don't need to make any changes since 11 is already the smallest non-negative integer that a=[2,2,2,0]a = [2, 2, 2, 0] does not contain.
  • To make the mex of aa equal to 22, we need to change the first three elements of aa. For example, we can change aa to be [3,1,1,0][3, 1, 1, 0].

SCORING:

  • Inputs 2-6: N103N\le 10^3
  • Inputs 7-11: No additional constraints.