結果

問題 No.945 YKC饅頭
ユーザー kimiyukikimiyuki
提出日時 2019-12-11 11:42:33
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 316 ms / 2,000 ms
コード長 2,599 bytes
コンパイル時間 3,012 ms
コンパイル使用メモリ 207,264 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-06 13:01:59
合計ジャッジ時間 14,483 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 3 ms
4,384 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 1 ms
4,384 KB
testcase_28 AC 1 ms
4,384 KB
testcase_29 AC 1 ms
4,384 KB
testcase_30 AC 2 ms
4,384 KB
testcase_31 AC 13 ms
4,380 KB
testcase_32 AC 7 ms
4,380 KB
testcase_33 AC 66 ms
4,384 KB
testcase_34 AC 169 ms
4,380 KB
testcase_35 AC 277 ms
4,380 KB
testcase_36 AC 210 ms
4,384 KB
testcase_37 AC 198 ms
4,380 KB
testcase_38 AC 182 ms
4,384 KB
testcase_39 AC 39 ms
4,384 KB
testcase_40 AC 34 ms
4,380 KB
testcase_41 AC 13 ms
4,380 KB
testcase_42 AC 252 ms
4,380 KB
testcase_43 AC 171 ms
4,380 KB
testcase_44 AC 203 ms
4,384 KB
testcase_45 AC 266 ms
4,380 KB
testcase_46 AC 6 ms
4,380 KB
testcase_47 AC 154 ms
4,384 KB
testcase_48 AC 33 ms
4,380 KB
testcase_49 AC 60 ms
4,384 KB
testcase_50 AC 268 ms
4,380 KB
testcase_51 AC 300 ms
4,380 KB
testcase_52 AC 312 ms
4,384 KB
testcase_53 AC 313 ms
4,380 KB
testcase_54 AC 316 ms
4,388 KB
testcase_55 AC 312 ms
4,384 KB
testcase_56 AC 6 ms
4,384 KB
testcase_57 AC 6 ms
4,380 KB
testcase_58 AC 146 ms
4,380 KB
testcase_59 AC 173 ms
4,384 KB
testcase_60 AC 63 ms
4,380 KB
testcase_61 AC 149 ms
4,380 KB
testcase_62 AC 145 ms
4,380 KB
testcase_63 AC 7 ms
4,384 KB
testcase_64 AC 70 ms
4,380 KB
testcase_65 AC 60 ms
4,384 KB
testcase_66 AC 50 ms
4,384 KB
testcase_67 AC 110 ms
4,380 KB
testcase_68 AC 69 ms
4,380 KB
testcase_69 AC 26 ms
4,380 KB
testcase_70 AC 31 ms
4,380 KB
testcase_71 AC 31 ms
4,384 KB
testcase_72 AC 89 ms
4,384 KB
testcase_73 AC 168 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) std::begin(x), std::end(x)
using namespace std;

/**
 * @brief a dual segment tree
 * @tparam Monoid (commutativity is not required)
 */
template <class Monoid>
struct dual_segment_tree {
    typedef typename Monoid::value_type value_type;
    const Monoid mon;
    int n;
    std::vector<value_type> f;
    dual_segment_tree() = default;
    dual_segment_tree(int n_, const Monoid & mon_ = Monoid()) : mon(mon_) {
        n = 1; while (n < n_) n *= 2;
        f.resize(2 * n - 1, mon.unit());
    }
    value_type point_get(int i) {  // 0-based
        assert (0 <= i and i < n);
        value_type acc = mon.unit();
        for (i += n; i > 0; i /= 2) {  // 1-based
            acc = mon.mult(f[i - 1], acc);
        }
        return acc;
    }
    void range_apply(int l, int r, value_type g) {  // 0-based, [l, r)
        assert (0 <= l and l <= r and r <= n);
        range_apply(0, 0, n, l, r, g);
    }
    void range_apply(int i, int il, int ir, int l, int r, value_type g) {
        if (l <= il and ir <= r) {  // 0-based
            f[i] = mon.mult(g, f[i]);
        } else if (ir <= l or r <= il) {
            // nop
        } else {
            range_apply(2 * i + 1, il, (il + ir) / 2, 0, n, f[i]);
            range_apply(2 * i + 2, (il + ir) / 2, ir, 0, n, f[i]);
            f[i] = mon.unit();
            range_apply(2 * i + 1, il, (il + ir) / 2, l, r, g);
            range_apply(2 * i + 2, (il + ir) / 2, ir, l, r, g);
        }
    }
};

template <class T>
struct right_monoid {
    // typedef std::optional<T> value_type;
    typedef std::pair<bool, T> value_type;
    value_type unit() const { return std::make_pair(false, T()); }
    value_type mult(value_type a, value_type b) const { return b.first ? b : a; }
};

int main() {
    int n, m; cin >> n >> m;
    dual_segment_tree<right_monoid<char> > segtree(n);
    while (m --) {
        int l, r; char x; cin >> l >> r >> x;
        -- l;
        segtree.range_apply(l, r, make_pair(true, x));
    }
    int y = 0;
    int k = 0;
    int c = 0;
    REP (i, n) {
        auto x = segtree.point_get(i);
        if (x.first) {
            if (x.second == 'Y') ++ y;
            if (x.second == 'K') ++ k;
            if (x.second == 'C') ++ c;
        }
    }
    cout << y << ' ' << k << ' ' << c << endl;
    return 0;
}
0