結果
| 問題 | No.2930 Larger Mex | 
| コンテスト | |
| ユーザー |  tnakao0123 | 
| 提出日時 | 2024-10-14 16:13:34 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 41 ms / 2,000 ms | 
| コード長 | 869 bytes | 
| コンパイル時間 | 531 ms | 
| コンパイル使用メモリ | 40,960 KB | 
| 最終ジャッジ日時 | 2025-02-24 19:32:01 | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 50 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:29:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |   scanf("%d%d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~
main.cpp:30:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |   for (int i = 0; i < n; i++) scanf("%d", as + i);
      |                               ~~~~~^~~~~~~~~~~~~~
            
            ソースコード
/* -*- coding: utf-8 -*-
 *
 * 2930.cc:  No.2930 Larger Mex - yukicoder
 */
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 200000;
const int MAX_M = 200000;
/* typedef */
/* global variables */
int as[MAX_N];
int cs[MAX_M], ds[MAX_N + 2];
/* subroutines */
/* main */
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  if (m == 0) {
    for (int k = n; k >= 1; k--) printf("%d\n", k);
    return 0;
  }
  
  int x = 0;
  for (int i = 0, j = 0; i < n; i++) {
    while (j < n && x < m) {
      if (as[j] < m && cs[as[j]]++ == 0) x++;
      j++;
    }
    if (x < m) break;
    ds[j - i]++, ds[n - i + 1]--;
    if (as[i] < m && --cs[as[i]] == 0) x--;
  }
  for (int k = 1; k <= n; k++) {
    ds[k] += ds[k - 1];
    printf("%d\n", ds[k]);
  }
  
  return 0;
}
            
            
            
        