結果

問題 No.945 YKC饅頭
ユーザー roarisroaris
提出日時 2019-12-08 10:55:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,374 ms / 2,000 ms
コード長 2,419 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 87,324 KB
実行使用メモリ 111,388 KB
最終ジャッジ日時 2023-08-28 16:36:01
合計ジャッジ時間 36,145 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,676 KB
testcase_01 AC 71 ms
71,720 KB
testcase_02 AC 93 ms
76,480 KB
testcase_03 AC 120 ms
77,568 KB
testcase_04 AC 89 ms
76,652 KB
testcase_05 AC 104 ms
77,300 KB
testcase_06 AC 116 ms
77,520 KB
testcase_07 AC 115 ms
77,548 KB
testcase_08 AC 89 ms
76,588 KB
testcase_09 AC 106 ms
77,232 KB
testcase_10 AC 114 ms
77,364 KB
testcase_11 AC 101 ms
76,640 KB
testcase_12 AC 108 ms
77,148 KB
testcase_13 AC 120 ms
77,436 KB
testcase_14 AC 119 ms
78,048 KB
testcase_15 AC 87 ms
76,476 KB
testcase_16 AC 97 ms
76,552 KB
testcase_17 AC 112 ms
77,620 KB
testcase_18 AC 124 ms
77,612 KB
testcase_19 AC 90 ms
76,500 KB
testcase_20 AC 89 ms
76,548 KB
testcase_21 AC 92 ms
76,476 KB
testcase_22 AC 122 ms
77,744 KB
testcase_23 AC 129 ms
77,836 KB
testcase_24 AC 119 ms
77,740 KB
testcase_25 AC 119 ms
78,000 KB
testcase_26 AC 124 ms
77,716 KB
testcase_27 AC 89 ms
76,716 KB
testcase_28 AC 88 ms
76,664 KB
testcase_29 AC 72 ms
71,552 KB
testcase_30 AC 70 ms
71,604 KB
testcase_31 AC 235 ms
81,384 KB
testcase_32 AC 296 ms
83,284 KB
testcase_33 AC 508 ms
91,992 KB
testcase_34 AC 712 ms
95,800 KB
testcase_35 AC 1,160 ms
108,476 KB
testcase_36 AC 675 ms
98,600 KB
testcase_37 AC 645 ms
97,268 KB
testcase_38 AC 687 ms
95,648 KB
testcase_39 AC 362 ms
86,016 KB
testcase_40 AC 435 ms
90,052 KB
testcase_41 AC 301 ms
83,072 KB
testcase_42 AC 930 ms
102,116 KB
testcase_43 AC 551 ms
96,824 KB
testcase_44 AC 936 ms
101,788 KB
testcase_45 AC 1,000 ms
106,372 KB
testcase_46 AC 230 ms
82,700 KB
testcase_47 AC 741 ms
95,592 KB
testcase_48 AC 269 ms
82,696 KB
testcase_49 AC 450 ms
88,268 KB
testcase_50 AC 1,045 ms
107,272 KB
testcase_51 AC 1,374 ms
111,252 KB
testcase_52 AC 1,330 ms
111,388 KB
testcase_53 AC 1,318 ms
111,380 KB
testcase_54 AC 1,321 ms
111,336 KB
testcase_55 AC 1,301 ms
111,272 KB
testcase_56 AC 288 ms
86,020 KB
testcase_57 AC 290 ms
86,208 KB
testcase_58 AC 772 ms
103,388 KB
testcase_59 AC 890 ms
106,576 KB
testcase_60 AC 535 ms
94,264 KB
testcase_61 AC 773 ms
104,288 KB
testcase_62 AC 783 ms
103,824 KB
testcase_63 AC 346 ms
87,356 KB
testcase_64 AC 544 ms
94,356 KB
testcase_65 AC 545 ms
93,268 KB
testcase_66 AC 528 ms
93,256 KB
testcase_67 AC 676 ms
98,496 KB
testcase_68 AC 547 ms
94,044 KB
testcase_69 AC 409 ms
88,784 KB
testcase_70 AC 424 ms
89,748 KB
testcase_71 AC 423 ms
89,948 KB
testcase_72 AC 577 ms
96,684 KB
testcase_73 AC 818 ms
105,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
INF = 2**31 - 1

class LazySegmentTree:
    def __init__(self, n):
        LV = (n-1).bit_length()
        self.N0 = 2 ** LV
        self.data = [INF] * (2*self.N0)
        self.lazy = [None] * (2*self.N0)
        
    def gindex(self, l, r):
        L = l + self.N0; R = r + self.N0
        lm = (L // (L & -L)) >> 1
        rm = (R // (R & -R)) >> 1
    
        while L < R:
            if R <= rm:
                yield R
            if L <= lm:
                yield L
            
            L >>= 1; R >>= 1
        
        while L:
            yield L
            L >>= 1

    def propagates(self, *ids):
        for i in reversed(ids):
            v = self.lazy[i-1]
            
            if v is None:
                continue
            
            self.lazy[2*i-1] = self.data[2*i-1] = self.lazy[2*i] = self.data[2*i] = v
            self.lazy[i-1] = None

    def update(self, l, r, x): #RUQ change a[l:r) to x
        *ids, = self.gindex(l, r)
        self.propagates(*ids)

        L = self.N0 + l; R = self.N0 + r
        
        while L < R:
            if R & 1:
                R -= 1
                self.lazy[R-1] = self.data[R-1] = x
            if L & 1:
                self.lazy[L-1] = self.data[L-1] = x
                L += 1
                
            L >>= 1; R >>= 1
            
        for i in ids:
            self.data[i-1] = min(self.data[2*i-1], self.data[2*i])

    def query(self, l, r): #RMQ min(a[l:r))
        self.propagates(*self.gindex(l, r))
        L = self.N0 + l; R = self.N0 + r

        s = INF
        
        while L < R:
            if R & 1:
                R -= 1
                s = min(s, self.data[R-1])
            if L & 1:
                s = min(s, self.data[L-1])
                L += 1
                
            L >>= 1; R >>= 1
        
        return s

N, M = map(int, input().split())
LRT = []

for _ in range(M):
    Li, Ri, Ti = input().split()
    Li, Ri = int(Li), int(Ri)
    
    if Ti=='Y':
        LRT.append((Li, Ri, 0))
    elif Ti=='K':
        LRT.append((Li, Ri, 1))
    elif Ti=='C':
        LRT.append((Li, Ri, 2))

LRT = LRT[::-1]
lst = LazySegmentTree(N)

for Li, Ri, Ti in LRT:
    lst.update(Li-1, Ri, Ti)

Y, K, C = 0, 0, 0

for i in range(N):
    v = lst.query(i, i+1)
    
    if v==0:
        Y += 1
    elif v==1:
        K += 1
    elif v==2:
        C += 1

print(Y, K, C)
0