結果

問題 No.945 YKC饅頭
ユーザー finefine
提出日時 2019-12-08 13:57:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 5,369 bytes
コンパイル時間 1,857 ms
コンパイル使用メモリ 180,212 KB
実行使用メモリ 7,320 KB
最終ジャッジ日時 2023-08-28 19:51:54
合計ジャッジ時間 9,591 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 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,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 14 ms
4,376 KB
testcase_32 AC 22 ms
4,380 KB
testcase_33 AC 57 ms
5,848 KB
testcase_34 AC 103 ms
5,372 KB
testcase_35 AC 176 ms
6,992 KB
testcase_36 AC 109 ms
4,728 KB
testcase_37 AC 105 ms
4,632 KB
testcase_38 AC 100 ms
4,792 KB
testcase_39 AC 34 ms
4,556 KB
testcase_40 AC 41 ms
5,664 KB
testcase_41 AC 21 ms
4,376 KB
testcase_42 AC 147 ms
5,696 KB
testcase_43 AC 91 ms
4,404 KB
testcase_44 AC 136 ms
6,788 KB
testcase_45 AC 159 ms
5,892 KB
testcase_46 AC 13 ms
4,384 KB
testcase_47 AC 102 ms
5,152 KB
testcase_48 AC 21 ms
4,380 KB
testcase_49 AC 51 ms
4,584 KB
testcase_50 AC 170 ms
5,928 KB
testcase_51 AC 211 ms
7,164 KB
testcase_52 AC 209 ms
7,196 KB
testcase_53 AC 213 ms
7,320 KB
testcase_54 AC 211 ms
7,252 KB
testcase_55 AC 210 ms
7,260 KB
testcase_56 AC 33 ms
5,612 KB
testcase_57 AC 32 ms
5,688 KB
testcase_58 AC 107 ms
6,644 KB
testcase_59 AC 124 ms
7,008 KB
testcase_60 AC 66 ms
6,216 KB
testcase_61 AC 119 ms
7,052 KB
testcase_62 AC 109 ms
6,732 KB
testcase_63 AC 34 ms
5,668 KB
testcase_64 AC 68 ms
6,196 KB
testcase_65 AC 61 ms
5,936 KB
testcase_66 AC 60 ms
6,128 KB
testcase_67 AC 88 ms
6,476 KB
testcase_68 AC 66 ms
6,160 KB
testcase_69 AC 43 ms
5,588 KB
testcase_70 AC 46 ms
5,588 KB
testcase_71 AC 47 ms
5,844 KB
testcase_72 AC 77 ms
6,140 KB
testcase_73 AC 119 ms
6,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

template <class MonoidOp>
struct LazySegmentTree {
    using Tm = typename MonoidOp::Tm;
    using To = typename MonoidOp::To;

    int n;
    vector<Tm> data;
    vector<To> lazy;

    LazySegmentTree() {}

    LazySegmentTree(int size, Tm initial_data_value = MonoidOp::unit()) {
        n = 1;
        while (n < size) n <<= 1;

        data.assign(2 * n - 1, initial_data_value);
        lazy.assign(2 * n - 1, MonoidOp::op_unit());

        if (initial_data_value != MonoidOp::unit()) {
            for (int i = n - 2; i >= 0; i--) data[i] = MonoidOp::merge(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }

    LazySegmentTree(const vector<Tm>& v) {
        int size = v.size();
        n = 1;
        while (n < size) n <<= 1;
        data.assign(2 * n - 1, MonoidOp::unit());
        lazy.assign(2 * n - 1, MonoidOp::op_unit());

        for (int i = 0; i < size; i++) data[i + n - 1] = v[i];
        for (int i = n - 2; i >= 0; i--) data[i] = MonoidOp::merge(data[i * 2 + 1], data[i * 2 + 2]);
    }

    Tm getLeaf(int k) {
        return query(k, k + 1);
    }

    void push(int k, int l, int r) {
        if (lazy[k] == MonoidOp::op_unit()) return;
        MonoidOp::apply(data[k], lazy[k], r - l);
        if (r - l > 1) {
            MonoidOp::update(lazy[2 * k + 1], lazy[k]);
            MonoidOp::update(lazy[2 * k + 2], lazy[k]);
        }
        lazy[k] = MonoidOp::op_unit();
    }

    //区間[a, b)に対する更新
    //k:節点番号, [l, r):節点に対応する区間
    void update(int a, int b, To x, int k, int l, int r) {
        push(k, l, r);
        //[a, b)と[l, r)が交差しない場合
        if (r <= a || b <= l) return;
        //[a, b)が[l, r)を含む場合、節点の値
        if (a <= l && r <= b) {
            MonoidOp::update(lazy[k], x);
            push(k, l, r);
        } else {
            update(a, b, x, k * 2 + 1, l, (l + r) / 2);
            update(a, b, x, k * 2 + 2, (l + r) / 2, r);
            data[k] = MonoidOp::merge(data[2 * k + 1], data[2 * k + 2]);
        }
    }

    void update(int a, int b, To x) {
        update(a, b, x, 0, 0, n);
    }

    //区間[a, b)に対するクエリに答える
    //k:節点番号, [l, r):節点に対応する区間
    Tm query(int a, int b, int k, int l, int r) {
        push(k, l, r);
        //[a, b)と[l, r)が交差しない場合
        if (r <= a || b <= l) return MonoidOp::unit();
        //[a, b)が[l, r)を含む場合、節点の値
        if (a <= l && r <= b) return data[k];
        else {
            //二つの子をマージ
            Tm vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            Tm vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return MonoidOp::merge(vl, vr);
        }
    }

    //外から呼ぶ用
    Tm query(int a, int b) {
        return query(a, b, 0, 0, n);
    }
};

// 以下、MonoidOpの例
template<class U = ll, class V = U>
struct RangeSumAdd {
    using Tm = U;
    using To = V;
    static Tm merge(Tm x, Tm y) { return x + y; }
    static void update(To& target, To x) { target += x; }
    static void apply(Tm& target, To x, int seg_len) { target += x * seg_len; }
    static constexpr Tm unit() { return Tm(0); }
    static constexpr To op_unit() { return To(0); }
};

// 作用素の単位元は更新クエリで与えられる値の定義域の範囲外の値にする
template<class U = ll, class V = U>
struct RangeMinUpdate {
    using Tm = U;
    using To = V;
    static Tm merge(Tm x, Tm y) { return min(x, y); }
    static void update(To& target, To x) { target = x; }
    static void apply(Tm& target, To x, int seg_len) { target = x; }
    static constexpr Tm unit() { return numeric_limits<Tm>::max(); }
    static constexpr To op_unit() { return numeric_limits<To>::max(); }
};

// 作用素の単位元は更新クエリで与えられる値の定義域の範囲外の値にする
template<class U = ll, class V = U>
struct RangeSumUpdate {
    using Tm = U;
    using To = V;
    static Tm merge(Tm x, Tm y) { return x + y; }
    static void update(To& target, To x) { target = x; }
    static void apply(Tm& target, To x, int seg_len) { target = x * seg_len; }
    static constexpr Tm unit() { return Tm(0); }
    static constexpr To op_unit() { return numeric_limits<To>::min(); }
};

// 初期値 != 単位元 の場合に注意
template<class U = ll, class V = U>
struct RangeMinAdd {
    using Tm = U;
    using To = V;
    static Tm merge(Tm x, Tm y) { return min(x, y); }
    static void update(To& target, To x) { target += x; }
    static void apply(Tm& target, To x, int seg_len) { target += x; }
    static constexpr Tm unit() { return numeric_limits<Tm>::max(); }
    static constexpr To op_unit() { return To(0); }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> L(m), R(m);
    vector<char> t(m);
    for (int i = 0; i < m; ++i) {
        cin >> L[i] >> R[i] >> t[i];
    }

    LazySegmentTree< RangeSumUpdate<int, char> > st(n);
    for (int i = m - 1; i >= 0; --i) {
        st.update(L[i] - 1, R[i], t[i]);
    }

    map<int, int> cnt;
    for (int i = 0; i < n; ++i) {
        cnt[st.query(i, i + 1)]++;
    }

    cout << cnt['Y'] << " " << cnt['K'] << " " << cnt['C'] << "\n";
    return 0;
}
0