結果

問題 No.2930 Larger Mex
ユーザー GOTKAKO
提出日時 2024-10-12 15:35:49
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 908 bytes
コンパイル時間 2,051 ms
コンパイル使用メモリ 203,632 KB
最終ジャッジ日時 2025-02-24 18:06:45
ジャッジサーバーID
(参考情報)
judge5 / judge
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,M; cin >> N >> M;
    vector<int> A(N);
    for(auto &a : A) cin >> a;

    vector<int> ap(200001);
    int pos = 0;
    set<int> zero;
    vector<long long> answer(N+2);
    for(int i=0; i<=200000; i++) zero.insert(i); 
    for(int i=0; i<N; i++){
        while(pos < N && *zero.begin() < M){
            int a = A.at(pos++);
            ap.at(a)++;
            if(ap.at(a) == 1) zero.erase(a);
        }
        if(*zero.begin() < M) break;
        pos = max(pos,i+1);
        answer.at(pos-i)++;
        answer.at(N-i+1)--; 
        if(M){
            int a = A.at(i);
            ap.at(a)--;
            if(ap.at(a) == 0) zero.insert(a);
        }
    }
    for(int i=2; i<=N; i++) answer.at(i) += answer.at(i-1);
    for(int i=1; i<=N; i++) cout << answer.at(i) << "\n";
}
0