結果

問題 No.945 YKC饅頭
ユーザー noriocnorioc
提出日時 2020-05-08 02:48:08
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 666 ms / 2,000 ms
コード長 1,718 bytes
コンパイル時間 2,105 ms
コンパイル使用メモリ 172,608 KB
実行使用メモリ 95,160 KB
最終ジャッジ日時 2023-09-04 07:42:41
合計ジャッジ時間 41,820 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 398 ms
71,420 KB
testcase_01 AC 398 ms
71,932 KB
testcase_02 AC 396 ms
71,744 KB
testcase_03 AC 401 ms
72,460 KB
testcase_04 AC 396 ms
72,220 KB
testcase_05 AC 401 ms
71,768 KB
testcase_06 AC 398 ms
71,716 KB
testcase_07 AC 400 ms
71,972 KB
testcase_08 AC 399 ms
72,064 KB
testcase_09 AC 397 ms
71,964 KB
testcase_10 AC 401 ms
71,772 KB
testcase_11 AC 397 ms
71,704 KB
testcase_12 AC 396 ms
72,056 KB
testcase_13 AC 399 ms
71,984 KB
testcase_14 AC 400 ms
72,228 KB
testcase_15 AC 398 ms
72,136 KB
testcase_16 AC 398 ms
71,884 KB
testcase_17 AC 398 ms
72,360 KB
testcase_18 AC 397 ms
71,856 KB
testcase_19 AC 402 ms
71,884 KB
testcase_20 AC 401 ms
71,956 KB
testcase_21 AC 403 ms
71,612 KB
testcase_22 AC 398 ms
72,228 KB
testcase_23 AC 399 ms
73,272 KB
testcase_24 AC 400 ms
72,376 KB
testcase_25 AC 399 ms
71,716 KB
testcase_26 AC 399 ms
71,892 KB
testcase_27 AC 395 ms
71,492 KB
testcase_28 AC 397 ms
71,416 KB
testcase_29 AC 396 ms
71,504 KB
testcase_30 AC 395 ms
72,136 KB
testcase_31 AC 407 ms
73,904 KB
testcase_32 AC 404 ms
72,264 KB
testcase_33 AC 438 ms
80,204 KB
testcase_34 AC 539 ms
88,040 KB
testcase_35 AC 617 ms
88,068 KB
testcase_36 AC 575 ms
88,104 KB
testcase_37 AC 565 ms
89,224 KB
testcase_38 AC 549 ms
87,560 KB
testcase_39 AC 423 ms
76,816 KB
testcase_40 AC 416 ms
74,248 KB
testcase_41 AC 403 ms
73,264 KB
testcase_42 AC 589 ms
88,644 KB
testcase_43 AC 559 ms
88,124 KB
testcase_44 AC 573 ms
87,332 KB
testcase_45 AC 613 ms
91,532 KB
testcase_46 AC 401 ms
72,336 KB
testcase_47 AC 541 ms
87,888 KB
testcase_48 AC 421 ms
76,304 KB
testcase_49 AC 439 ms
79,532 KB
testcase_50 AC 619 ms
92,728 KB
testcase_51 AC 665 ms
95,160 KB
testcase_52 AC 666 ms
94,312 KB
testcase_53 AC 664 ms
94,028 KB
testcase_54 AC 664 ms
95,116 KB
testcase_55 AC 657 ms
94,024 KB
testcase_56 AC 402 ms
71,548 KB
testcase_57 AC 402 ms
71,480 KB
testcase_58 AC 566 ms
87,852 KB
testcase_59 AC 595 ms
89,772 KB
testcase_60 AC 458 ms
83,980 KB
testcase_61 AC 572 ms
88,092 KB
testcase_62 AC 568 ms
88,912 KB
testcase_63 AC 401 ms
72,408 KB
testcase_64 AC 464 ms
84,904 KB
testcase_65 AC 446 ms
81,676 KB
testcase_66 AC 449 ms
79,996 KB
testcase_67 AC 532 ms
87,828 KB
testcase_68 AC 458 ms
83,712 KB
testcase_69 AC 416 ms
74,004 KB
testcase_70 AC 423 ms
76,264 KB
testcase_71 AC 421 ms
77,620 KB
testcase_72 AC 477 ms
87,040 KB
testcase_73 AC 588 ms
88,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

const segSize = 1 << 20;
int[][] seg;

void update(int l, int r, int v, int time) {
    l += segSize;
    r += segSize;
    while (l < r) {
        if (l % 2 == 1) {
            seg[l][v] = time;
            l++;
        }
        l /= 2;
        if (r % 2 == 1) {
            seg[r - 1][v] = time;
            r--;
        }
        r /= 2;
    }
}

// 親の更新を子に伝搬する(親は更新されない)
void propagate() {
    void rec(int ind) {
        // 子がいない
        if (ind * 2 >= seg.length) return;

        int lt = ind * 2;
        int rt = ind * 2 + 1;
        foreach (i; 0..3) { // Y, K, C
            seg[lt][i] = max(seg[lt][i], seg[ind][i]);
            seg[rt][i] = max(seg[rt][i], seg[ind][i]);
        }
        rec(lt);
        rec(rt);
    }
    rec(1);
}

alias Q = Tuple!(int, "l", int, "r", int, "t");

int toInt(string c) {
    if (c == "Y") return 0;
    if (c == "K") return 1;
    return 2;
}

void main() {
    int n, m; scan(n, m);

    seg = new int[][](segSize * 2, 3);
    Q[] qs;
    foreach (_; 0..m) {
        int l, r; string t; scan(l, r, t);
        qs ~= Q(l, r, toInt(t));
    }

    int time = 1;
    foreach_reverse (q; qs) {
        update(q.l, q.r + 1, q.t, time++);
    }

    propagate();
    auto ans = [0, 0, 0];
    auto nodes = seg[segSize+1..$].take(n);
    foreach (e; nodes) {
        if (e.sum == 0) continue; // 饅頭がない
        ans[e.maxIndex]++;
    }
    writeln(ans.map!text.join(' '));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T=string)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readints = reads!int;
0