結果

問題 No.2930 Larger Mex
ユーザー detteiuu
提出日時 2024-10-12 16:41:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 639 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 82,492 KB
実行使用メモリ 110,604 KB
最終ジャッジ日時 2024-10-12 16:41:52
合計ジャッジ時間 8,245 ms
ジャッジサーバーID
(参考情報)
judge / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
A = list(map(int, input().split()))

if M == 0:
    for i in reversed(range(1, N+1)):
        print(i)
    exit()

right = 0
cnt = 0
C = [0]*(10**5*2+1)
ans = [0]*(N+1)
for left in range(N):
    while right < N and cnt < M:
        C[A[right]] += 1
        if A[right] < M and C[A[right]] == 1:
            cnt += 1
        right += 1
    if cnt >= M:
        ans[right-left-1] += 1
        ans[N-left] -= 1
    if left == right:
        right += 1
    C[A[left]] -= 1
    if A[left] < M and C[A[left]] == 0:
        cnt -= 1

for i in range(1, N+1):
    ans[i] += ans[i-1]

for a in ans[:-1]:
    print(a)
0