結果

問題 No.945 YKC饅頭
ユーザー tnakao0123tnakao0123
提出日時 2019-12-08 20:16:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 1,999 bytes
コンパイル時間 713 ms
コンパイル使用メモリ 84,000 KB
実行使用メモリ 7,608 KB
最終ジャッジ日時 2023-08-30 04:09:28
合計ジャッジ時間 7,128 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,496 KB
testcase_01 AC 2 ms
5,552 KB
testcase_02 AC 2 ms
5,496 KB
testcase_03 AC 3 ms
5,508 KB
testcase_04 AC 2 ms
5,556 KB
testcase_05 AC 2 ms
5,592 KB
testcase_06 AC 2 ms
5,840 KB
testcase_07 AC 2 ms
5,672 KB
testcase_08 AC 2 ms
5,552 KB
testcase_09 AC 2 ms
5,620 KB
testcase_10 AC 2 ms
5,600 KB
testcase_11 AC 2 ms
5,652 KB
testcase_12 AC 3 ms
5,648 KB
testcase_13 AC 2 ms
5,548 KB
testcase_14 AC 3 ms
5,848 KB
testcase_15 AC 2 ms
5,728 KB
testcase_16 AC 2 ms
5,548 KB
testcase_17 AC 3 ms
5,500 KB
testcase_18 AC 2 ms
5,500 KB
testcase_19 AC 2 ms
5,588 KB
testcase_20 AC 2 ms
5,664 KB
testcase_21 AC 2 ms
5,612 KB
testcase_22 AC 3 ms
5,608 KB
testcase_23 AC 2 ms
5,856 KB
testcase_24 AC 2 ms
5,672 KB
testcase_25 AC 2 ms
5,656 KB
testcase_26 AC 3 ms
5,524 KB
testcase_27 AC 2 ms
5,524 KB
testcase_28 AC 2 ms
5,672 KB
testcase_29 AC 2 ms
5,576 KB
testcase_30 AC 2 ms
5,500 KB
testcase_31 AC 7 ms
5,872 KB
testcase_32 AC 4 ms
6,812 KB
testcase_33 AC 28 ms
6,700 KB
testcase_34 AC 71 ms
6,408 KB
testcase_35 AC 116 ms
7,304 KB
testcase_36 AC 88 ms
5,756 KB
testcase_37 AC 83 ms
5,740 KB
testcase_38 AC 76 ms
5,852 KB
testcase_39 AC 17 ms
6,240 KB
testcase_40 AC 15 ms
6,712 KB
testcase_41 AC 7 ms
6,352 KB
testcase_42 AC 105 ms
6,460 KB
testcase_43 AC 75 ms
5,724 KB
testcase_44 AC 89 ms
6,696 KB
testcase_45 AC 119 ms
6,348 KB
testcase_46 AC 3 ms
6,104 KB
testcase_47 AC 69 ms
6,408 KB
testcase_48 AC 17 ms
5,956 KB
testcase_49 AC 29 ms
6,340 KB
testcase_50 AC 122 ms
6,520 KB
testcase_51 AC 138 ms
7,608 KB
testcase_52 AC 139 ms
7,464 KB
testcase_53 AC 140 ms
7,400 KB
testcase_54 AC 140 ms
7,464 KB
testcase_55 AC 139 ms
7,380 KB
testcase_56 AC 4 ms
7,208 KB
testcase_57 AC 3 ms
5,868 KB
testcase_58 AC 69 ms
7,180 KB
testcase_59 AC 83 ms
7,212 KB
testcase_60 AC 31 ms
7,052 KB
testcase_61 AC 73 ms
7,108 KB
testcase_62 AC 69 ms
7,192 KB
testcase_63 AC 5 ms
7,068 KB
testcase_64 AC 34 ms
7,144 KB
testcase_65 AC 28 ms
7,144 KB
testcase_66 AC 26 ms
6,996 KB
testcase_67 AC 51 ms
6,996 KB
testcase_68 AC 32 ms
6,992 KB
testcase_69 AC 13 ms
7,032 KB
testcase_70 AC 16 ms
7,032 KB
testcase_71 AC 16 ms
7,028 KB
testcase_72 AC 42 ms
7,280 KB
testcase_73 AC 79 ms
7,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 945.cc:  No.945 YKC饅頭 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int MAX_E2 = 1 << 19; // = 524288
const int MAX_M = 200000;

/* typedef */

enum { NA, Y, K, C };

template <typename T, const int MAX_E2>
struct SegTree {
  int n, e2;
  T nodes[MAX_E2];
  SegTree() {}

  void init(int _n) {
    n = _n;
    for (e2 = 1; e2 < n; e2 <<= 1);
  }

  T &get(int i) { return nodes[e2 - 1 + i]; }

  void setall() {
    for (int j = 0; j < e2 - 1; j++)
      if (nodes[j]) {
	nodes[j * 2 + 1] = nodes[j * 2 + 2] = nodes[j];
	nodes[j] = NA;
      }
  }

  void set_range(int r0, int r1, T v, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return;
    if (r0 <= i0 && i1 <= r1) {
      nodes[k] = v;
      return;
    }

    int k0 = k * 2 + 1, k1 = k0 + 1;
    if (nodes[k]) {
      nodes[k0] = nodes[k1] = nodes[k];
      nodes[k] = NA;
    }

    int im = (i0 + i1) / 2;
    set_range(r0, r1, v, k0, i0, im);
    set_range(r0, r1, v, k1, im, i1);
  }
  void set_range(int r0, int r1, T v) { set_range(r0, r1, v, 0, 0, e2); }
};

/* global variables */

int cmap[128];
int ls[MAX_M], rs[MAX_M], ts[MAX_M], cs[4];
SegTree<int,MAX_E2> st;

/* subroutines */

/* main */

int main() {
  cmap['Y'] = Y, cmap['K'] = K, cmap['C'] = C;

  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < m; i++) {
    char s[4];
    scanf("%d%d%s", ls + i, rs + i, s);
    ls[i]--;
    ts[i] = cmap[s[0]];
  }

  st.init(n);

  for (int i = m - 1; i >= 0; i--)
    st.set_range(ls[i], rs[i], ts[i]);

  st.setall();

  for (int i = 0; i < n; i++) cs[st.get(i)]++;
  printf("%d %d %d\n", cs[Y], cs[K], cs[C]);
  return 0;
}
0