Making Mexes

시간 제한2초메모리 제한2048 MB

요약
각 i=0부터 N까지, 배열이 0부터 i-1을 모두 포함하고 i를 포함하지 않도록 바꿔야 하는 원소 개수의 최솟값을 구한다.
난이도

보통10점 중 6점

유형
그리디, 누적 합, 정렬
정답자
아직 제출이 없습니다

문제

You are given an array aa of NN non-negative integers a_1,a_2,…,a_Na\_1, a\_2, \dots, a\_N (1≤N≤2⋅105,0≤a_i≤N1\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.

입력

The first line contains NN.

The next line contains a_1,a_2,…,a_Na\_1,a\_2,\dots, a\_N.

출력

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.

예제1

  1. 예제 1

    입력
    4
    2 2 2 0
    
    예상 출력
    1
    0
    3
    1
    2