結果

問題 No.945 YKC饅頭
ユーザー 👑 emthrmemthrm
提出日時 2019-12-08 00:04:55
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 492 ms / 2,000 ms
コード長 4,239 bytes
コンパイル時間 1,667 ms
コンパイル使用メモリ 136,068 KB
最終ジャッジ日時 2025-01-08 09:39:05
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 74
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
//           dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
template <typename Monoid>
struct RMQandRUQ {
  RMQandRUQ(int sz, const Monoid &UNITY) : UNITY(UNITY) {
    init(sz);
    dat.assign((n << 1) - 1, UNITY);
  }

  RMQandRUQ(const vector<Monoid> &a, const Monoid &UNITY) : UNITY(UNITY) {
    int a_sz = a.size();
    init(a_sz);
    dat.resize((n << 1) - 1);
    REP(i, a_sz) dat[n - 1 + i] = a[i];
    for (int i = n - 2; i >= 0; --i) dat[i] = min(dat[(i << 1) + 1], dat[(i << 1) + 2]);
  }

  void update(int a, int b, const Monoid &value) { update(a, b, value, 0, 0, n); }

  Monoid query(int a, int b) { return query(a, b, 0, 0, n); }

  Monoid operator[](const int idx) { return query(idx, idx + 1); }

  int find(int a, int b, const Monoid &value) { return find(a, b, value, 0, 0, n); }

private:
  int n = 1;
  const Monoid UNITY;
  vector<Monoid> dat, lazy;
  vector<bool> need_to_be_eval;

  void init(int sz) {
    while (n < sz) n <<= 1;
    lazy.assign((n << 1) - 1, UNITY);
    need_to_be_eval.assign((n << 1) - 1, false);
  }

  inline void evaluate(int node, int left, int right) {
    if (need_to_be_eval[node]) {
      dat[node] = lazy[node];
      if (node < n - 1) {
        lazy[(node << 1) + 1] = lazy[(node << 1) + 2] = lazy[node];
        need_to_be_eval[(node << 1) + 1] = need_to_be_eval[(node << 1) + 2] = true;
      }
      lazy[node] = UNITY;
      need_to_be_eval[node] = false;
    }
  }

  void update(int a, int b, const Monoid &value, int node, int left, int right) {
    evaluate(node, left, right);
    if (right <= a || b <= left) return;
    if (a <= left && right <= b) {
      lazy[node] = value;
      need_to_be_eval[node] = true;
      evaluate(node, left, right);
    } else {
      update(a, b, value, (node << 1) + 1, left, (left + right) >> 1);
      update(a, b, value, (node << 1) + 2, (left + right) >> 1, right);
      dat[node] = min(dat[(node << 1) + 1], dat[(node << 1) + 2]);
    }
  }

  Monoid query(int a, int b, int node, int left, int right) {
    evaluate(node, left, right);
    if (right <= a || b <= left) return UNITY;
    if (a <= left && right <= b) return dat[node];
    return min(query(a, b, (node << 1) + 1, left, (left + right) >> 1), query(a, b, (node << 1) + 2, (left + right) >> 1, right));
  }

  int find(int a, int b, const Monoid &value, int node, int left, int right) {
    evaluate(node, left, right);
    if (dat[node] > value || right <= a || b <= left) return -1;
    if (right - left == 1) return node - (n - 1);
    int res_l = find(a, b, value, (node << 1) + 1, left, (left + right) >> 1);
    if (res_l != -1) return res_l;
    return find(a, b, value, (node << 1) + 2, (left + right) >> 1, right);
  }
};

int main() {
  int n, m; cin >> n >> m;
  vector<int> l(m), r(m), t(m);
  map<char, int> mp;
  mp['Y'] = 0; mp['K'] = 1; mp['C'] = 2;
  REP(i, m) {
    char c; cin >> l[i] >> r[i] >> c; --l[i]; --r[i];
    t[i] = mp[c];
  }
  RMQandRUQ<int> ruq(n, INF);
  for (int i = m - 1; i >= 0; --i) ruq.update(l[i], r[i] + 1, t[i]);
  vector<int> ans(3, 0);
  REP(i, n) {
    if (ruq[i] <= 2) ++ans[ruq[i]];
  }
  REP(i, 3) cout << ans[i] << (i + 1 == 3 ? '\n' : ' ');
  return 0;
}
0