結果
問題 |
No.2930 Larger Mex
|
ユーザー |
![]() |
提出日時 | 2024-10-16 20:35:03 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 957 bytes |
コンパイル時間 | 666 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 65,408 KB |
最終ジャッジ日時 | 2024-10-16 20:35:10 |
合計ジャッジ時間 | 6,945 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 3 |
other | RE * 50 |
ソースコード
from sortedcontainers import SortedSet N, M = map(int, input().split()) if M == 0: for i in range(N): print(N - i) exit() def mex(): if NS == 0: return -1 lb = -1 ub = NS + 1 while ub - lb > 1: mid = (ub + lb) // 2 if mid >= NS or S[mid] > mid: ub = mid else: lb = mid return ub A = list(map(int, input().split())) S = SortedSet() dic = {} imos = [0] * (N + 1) j = 0 NS = 0 mexn = -1 for i in range(N): while j < N and mexn < M: a = A[j] if a in dic: dic[a] += 1 else: dic[a] = 1 S.add(a) NS += 1 j += 1 mexn = mex() if mexn >= M: imos[j - i - 1] += 1 imos[N - i] -= 1 a = A[i] dic[a] -= 1 if dic[a] == 0: dic.pop(a) S.remove(a) NS -= 1 mexn = mex() now = 0 for i in range(N): now += imos[i] print(now)