結果

問題 No.945 YKC饅頭
ユーザー brthyyjpbrthyyjp
提出日時 2021-06-03 22:55:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,407 ms / 2,000 ms
コード長 3,288 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 123,672 KB
最終ジャッジ日時 2024-11-17 12:27:33
合計ジャッジ時間 35,412 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,480 KB
testcase_01 AC 39 ms
52,736 KB
testcase_02 AC 64 ms
67,712 KB
testcase_03 AC 95 ms
76,160 KB
testcase_04 AC 60 ms
65,792 KB
testcase_05 AC 76 ms
73,956 KB
testcase_06 AC 94 ms
75,904 KB
testcase_07 AC 87 ms
76,032 KB
testcase_08 AC 60 ms
65,024 KB
testcase_09 AC 78 ms
72,960 KB
testcase_10 AC 93 ms
76,172 KB
testcase_11 AC 74 ms
71,424 KB
testcase_12 AC 85 ms
76,032 KB
testcase_13 AC 91 ms
76,068 KB
testcase_14 AC 95 ms
75,776 KB
testcase_15 AC 59 ms
65,024 KB
testcase_16 AC 71 ms
70,400 KB
testcase_17 AC 91 ms
76,544 KB
testcase_18 AC 91 ms
75,776 KB
testcase_19 AC 62 ms
67,840 KB
testcase_20 AC 62 ms
66,176 KB
testcase_21 AC 62 ms
66,468 KB
testcase_22 AC 95 ms
76,560 KB
testcase_23 AC 96 ms
76,396 KB
testcase_24 AC 99 ms
76,288 KB
testcase_25 AC 97 ms
75,904 KB
testcase_26 AC 97 ms
76,188 KB
testcase_27 AC 60 ms
66,432 KB
testcase_28 AC 63 ms
66,816 KB
testcase_29 AC 41 ms
52,480 KB
testcase_30 AC 42 ms
52,736 KB
testcase_31 AC 243 ms
81,100 KB
testcase_32 AC 264 ms
81,408 KB
testcase_33 AC 525 ms
92,384 KB
testcase_34 AC 751 ms
101,304 KB
testcase_35 AC 1,249 ms
116,820 KB
testcase_36 AC 710 ms
107,568 KB
testcase_37 AC 707 ms
103,532 KB
testcase_38 AC 703 ms
101,112 KB
testcase_39 AC 380 ms
85,816 KB
testcase_40 AC 444 ms
89,088 KB
testcase_41 AC 300 ms
82,880 KB
testcase_42 AC 994 ms
111,044 KB
testcase_43 AC 585 ms
105,376 KB
testcase_44 AC 989 ms
108,716 KB
testcase_45 AC 1,054 ms
116,540 KB
testcase_46 AC 200 ms
81,424 KB
testcase_47 AC 760 ms
100,212 KB
testcase_48 AC 274 ms
82,964 KB
testcase_49 AC 477 ms
88,816 KB
testcase_50 AC 1,104 ms
117,420 KB
testcase_51 AC 1,407 ms
123,672 KB
testcase_52 AC 1,393 ms
123,600 KB
testcase_53 AC 1,379 ms
123,544 KB
testcase_54 AC 1,395 ms
123,352 KB
testcase_55 AC 1,387 ms
123,540 KB
testcase_56 AC 264 ms
85,120 KB
testcase_57 AC 263 ms
85,632 KB
testcase_58 AC 837 ms
109,896 KB
testcase_59 AC 940 ms
116,560 KB
testcase_60 AC 554 ms
96,080 KB
testcase_61 AC 833 ms
111,816 KB
testcase_62 AC 794 ms
110,404 KB
testcase_63 AC 318 ms
86,576 KB
testcase_64 AC 564 ms
97,108 KB
testcase_65 AC 536 ms
94,412 KB
testcase_66 AC 521 ms
94,100 KB
testcase_67 AC 761 ms
102,728 KB
testcase_68 AC 563 ms
97,172 KB
testcase_69 AC 445 ms
89,468 KB
testcase_70 AC 449 ms
89,884 KB
testcase_71 AC 437 ms
89,672 KB
testcase_72 AC 616 ms
99,184 KB
testcase_73 AC 906 ms
114,876 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())

    seg = 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':
            seg.update(l, r+1, 1)
        if t == 'K':
            seg.update(l, r+1, 2)
        if t == 'C':
            seg.update(l, r+1, 3)

    ans = [0]*3
    for i in range(n):
        t = seg.query(i, i+1)
        if t != INF:
            ans[t-1] += 1
    print(*ans)

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