結果
| 問題 | No.2930 Larger Mex | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2024-12-12 00:09:29 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 336 ms / 2,000 ms | 
| コード長 | 1,722 bytes | 
| コンパイル時間 | 1,243 ms | 
| コンパイル使用メモリ | 117,176 KB | 
| 最終ジャッジ日時 | 2025-02-26 12:02:22 | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 50 | 
ソースコード
#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<cassert>
#include<random>
#include<set>
#include<map>
#include<cassert>
#include<unordered_map>
#include<bitset>
#include<numeric>
#include<algorithm>
using namespace std;
using ll = long long;
const int inf=1<<30;
const ll INF=1LL<<62;
typedef pair<int,ll> P;
typedef pair<int,P> PP; 
const ll MOD=998244353;
const int dy[]={0,1,0,-1};
const int dx[]={1,0,-1,0};
int main(){
    int N,M;
    cin>>N>>M;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    if(M==0){
        for(int k=1;k<=N;k++){
            cout<<N-k+1<<endl;
        }
        return 0;
    }
    int cnt_lower=0;//{0,1,2,...,M-1}が全て登場したかどうかをcnt_lowerで管理する
    vector<int> cnt_appear(M+1,0);// cnt_appear[i]=数iが登場した回数
    vector<ll> cum_sum(N+5,0);
    int l=0,r=0;
    while(l<N){
        while(r<N && cnt_lower<M){
            if(A[r]<M){
                if(cnt_appear[A[r]]==0){
                    cnt_lower++;//[l,r)にA[r]が初めて登場した
                }
                cnt_appear[A[r]]++;
            }
            r++;
        }
        
        if(cnt_lower==M){
            //[l,r)
            int len=r-l;
            cum_sum[len]++;//len以上は条件を満たす
            cum_sum[N+1-l]--;//[l,N+1)
        }
        if(A[l]<M){
            cnt_appear[A[l]]--;
            if(cnt_appear[A[l]]==0){
                cnt_lower--;
            }
        }
        l++;
    }
    for(int i=1;i<=N;i++){
        cum_sum[i]+=cum_sum[i-1];
    }
    vector<ll> ans(N+1,0);
    for(int i=1;i<=N;i++){
        ans[i]=cum_sum[i];
        cout<<ans[i]<<endl;
    }
    
}
            
            
            
        