結果

問題 No.2930 Larger Mex
ユーザー applejam
提出日時 2025-01-24 00:06:50
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 273 ms / 2,000 ms
コード長 1,022 bytes
コンパイル時間 2,949 ms
コンパイル使用メモリ 132,820 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-01-24 00:07:10
合計ジャッジ時間 18,104 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;
#define rep(i, n) for (int i = 0; i< (int)(n); i++) 

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n, m; cin >> n >> m;
    vector<int> a(n); rep(i, n)cin >> a[i];
    if(m == 0){
        rep(i, n)cout << n - i << endl;
        return 0;
    }
    vector<int> ans(n+1, 0), cnt(m, 0);
    int itr = 0; int sz = 0;
    rep(i, n){
        while(itr < n && sz < m){
            if(a[itr] < m){
                if(cnt[a[itr]] == 0)sz++;
                cnt[a[itr]]++;
            }
            itr++;
        }
        if(sz == m){
            ans[itr-i]++;
            if(i > 0)ans[n + 1-i]--;
        }
        if(a[i] < m){
            cnt[a[i]]--;
            if(cnt[a[i]] == 0)sz--;
        }
    }
    int res = 0;
    rep(i, n){
        res += ans[i+1];
        cout << res << endl;
    }

    return 0;
}
0