結果

問題 No.945 YKC饅頭
ユーザー brthyyjpbrthyyjp
提出日時 2021-06-03 22:52:08
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,585 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 82,332 KB
実行使用メモリ 144,776 KB
最終ジャッジ日時 2024-04-28 17:55:18
合計ジャッジ時間 54,348 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,924 KB
testcase_01 AC 45 ms
53,692 KB
testcase_02 AC 73 ms
72,436 KB
testcase_03 AC 105 ms
76,724 KB
testcase_04 AC 62 ms
68,084 KB
testcase_05 AC 89 ms
75,704 KB
testcase_06 AC 105 ms
76,312 KB
testcase_07 AC 98 ms
76,216 KB
testcase_08 AC 67 ms
69,776 KB
testcase_09 AC 84 ms
75,524 KB
testcase_10 AC 104 ms
76,588 KB
testcase_11 AC 88 ms
76,044 KB
testcase_12 AC 100 ms
76,152 KB
testcase_13 AC 111 ms
76,780 KB
testcase_14 AC 105 ms
76,352 KB
testcase_15 AC 61 ms
66,552 KB
testcase_16 AC 73 ms
74,092 KB
testcase_17 AC 92 ms
76,148 KB
testcase_18 AC 102 ms
76,484 KB
testcase_19 AC 78 ms
76,068 KB
testcase_20 AC 67 ms
70,768 KB
testcase_21 AC 69 ms
69,380 KB
testcase_22 AC 111 ms
76,072 KB
testcase_23 AC 107 ms
76,616 KB
testcase_24 AC 108 ms
76,268 KB
testcase_25 AC 108 ms
76,020 KB
testcase_26 AC 107 ms
76,712 KB
testcase_27 AC 79 ms
75,960 KB
testcase_28 AC 77 ms
75,760 KB
testcase_29 AC 40 ms
52,740 KB
testcase_30 AC 41 ms
53,788 KB
testcase_31 AC 360 ms
86,272 KB
testcase_32 AC 588 ms
91,696 KB
testcase_33 AC 932 ms
109,852 KB
testcase_34 AC 1,076 ms
111,512 KB
testcase_35 AC 1,773 ms
136,204 KB
testcase_36 AC 843 ms
111,956 KB
testcase_37 AC 868 ms
107,860 KB
testcase_38 AC 886 ms
108,416 KB
testcase_39 AC 638 ms
95,248 KB
testcase_40 AC 865 ms
106,664 KB
testcase_41 AC 559 ms
91,840 KB
testcase_42 AC 1,355 ms
123,572 KB
testcase_43 AC 702 ms
108,796 KB
testcase_44 AC 1,450 ms
128,292 KB
testcase_45 AC 1,339 ms
129,064 KB
testcase_46 AC 403 ms
90,696 KB
testcase_47 AC 1,153 ms
111,128 KB
testcase_48 AC 350 ms
84,904 KB
testcase_49 AC 780 ms
99,260 KB
testcase_50 AC 1,461 ms
129,940 KB
testcase_51 AC 1,978 ms
144,776 KB
testcase_52 TLE -
testcase_53 AC 1,949 ms
144,000 KB
testcase_54 TLE -
testcase_55 TLE -
testcase_56 AC 629 ms
105,300 KB
testcase_57 AC 627 ms
104,964 KB
testcase_58 AC 1,350 ms
130,404 KB
testcase_59 AC 1,551 ms
136,436 KB
testcase_60 AC 1,072 ms
113,784 KB
testcase_61 AC 1,401 ms
131,444 KB
testcase_62 TLE -
testcase_63 AC 745 ms
105,544 KB
testcase_64 AC 1,091 ms
114,812 KB
testcase_65 AC 1,020 ms
113,008 KB
testcase_66 AC 985 ms
111,588 KB
testcase_67 AC 1,321 ms
122,724 KB
testcase_68 AC 1,071 ms
114,020 KB
testcase_69 AC 970 ms
107,788 KB
testcase_70 AC 907 ms
108,452 KB
testcase_71 AC 932 ms
108,080 KB
testcase_72 AC 1,128 ms
117,760 KB
testcase_73 AC 1,521 ms
134,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class LazySegTree:
    # RMQ and RUQ
    def __init__(self, init_val, seg_ide, lazy_ide, segfunc):
        self.n = len(init_val)
        self.num = 2**(self.n-1).bit_length()

        self.seg_ide = seg_ide
        self.lazy_ide = lazy_ide

        self.segfunc = segfunc

        # seg, lazy: 1-indexed
        self.seg = [seg_ide]*2*self.num
        for i in range(self.n):
            self.seg[i+self.num] = init_val[i]
        for i in range(self.num-1, 0, -1):
            self.seg[i] = self.segfunc(self.seg[2*i], self.seg[2*i+1])

        self.lazy = [lazy_ide]*2*self.num

    def gindex(self, l, r):
        # l, r: 1-indexed
        L = l + self.num
        R = r + self.num
        lm = (L // (L & -L)) >> 1
        rm = (R // (R & -R)) >> 1
        while L < R:
            if R <= rm:
                yield R
            if L <= lm:
                yield L
            L = L >> 1
            R = R >> 1
        while L:
            yield L
            L = L >> 1

    def propagate(self, *ids):
        # ids: 1-indexed
        for i in reversed(ids):
            v = self.lazy[i]
            if v is None:
                continue
            self.lazy[2*i] = self.lazy[2*i+1] = self.seg[2*i] = self.seg[2*i+1] = v
            self.lazy[i] = None

    def update(self, l, r, x):
        # l, r: 0-indexed
        # change x to [l, r)
        *ids, = self.gindex(l, r)
        self.propagate(*ids)
        L = l + self.num
        R = r + self.num
        while L < R:
            if R & 1:
                R -= 1
                self.lazy[R] = self.seg[R] = x
            if L & 1:
                self.lazy[L] = self.seg[L] = x
                L += 1
            L = L >> 1
            R = R >> 1
        for i in ids:
            # i: 1-indexed
            self.seg[i] = self.segfunc(self.seg[2*i], self.seg[2*i+1])

    def query(self, l, r):
        # l, r: 0-indexed
        # query for [l, r)
        if r <= l:
            return self.seg_ide

        self.propagate(*self.gindex(l, r))
        L = l + self.num
        R = r + self.num
        res = self.seg_ide
        while L < R:
            if R & 1:
                R -= 1
                res = self.segfunc(res, self.seg[R])
            if L & 1:
                res = self.segfunc(self.seg[L], res)
                L += 1
            L = L >> 1
            R = R >> 1
        return res

    def __str__(self): # for debug
        arr = [self.query(i,i+1) for i in range(self.n)]
        return str(arr)

def segfunc(x, y):
    if x <= y:
        return x
    else:
        return y

import sys
import io, os
input = sys.stdin.readline

INF = 10**18

def main():
    n, m = map(int, input().split())

    segy = LazySegTree([INF]*n, INF, None, segfunc)
    segk = LazySegTree([INF]*n, INF, None, segfunc)
    segc = LazySegTree([INF]*n, INF, None, segfunc)

    Q = []
    for i in range(m):
        l, r, t = map(str, input().split())
        l, r = int(l), int(r)
        l, r = l-1, r-1
        Q.append((l, r, t))

    for i in reversed(range(m)):
        l, r, t = Q[i]
        if t == 'Y':
            segy.update(l, r+1, i)
        if t == 'K':
            segk.update(l, r+1, i)
        if t == 'C':
            segc.update(l, r+1, i)

    y = 0
    k = 0
    c = 0
    for i in range(n):
        yi = segy.query(i, i+1)
        ki = segk.query(i, i+1)
        ci = segc.query(i, i+1)
        if yi < ki and yi < ci:
            y += 1
        if ki < yi and ki < ci:
            k += 1
        if ci < yi and ci < ki:
            c += 1
    print(y, k, c)

if __name__ == '__main__':
    main()
0