結果

問題 No.945 YKC饅頭
ユーザー roarisroaris
提出日時 2019-12-09 00:59:18
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,335 ms / 2,000 ms
コード長 2,454 bytes
コンパイル時間 574 ms
コンパイル使用メモリ 87,256 KB
実行使用メモリ 110,068 KB
最終ジャッジ日時 2023-08-30 23:49:01
合計ジャッジ時間 38,730 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,336 KB
testcase_01 AC 68 ms
71,528 KB
testcase_02 AC 89 ms
76,576 KB
testcase_03 AC 116 ms
77,516 KB
testcase_04 AC 89 ms
76,504 KB
testcase_05 AC 103 ms
77,192 KB
testcase_06 AC 116 ms
77,368 KB
testcase_07 AC 113 ms
77,488 KB
testcase_08 AC 88 ms
76,508 KB
testcase_09 AC 107 ms
77,104 KB
testcase_10 AC 115 ms
77,300 KB
testcase_11 AC 101 ms
76,640 KB
testcase_12 AC 109 ms
77,156 KB
testcase_13 AC 119 ms
77,348 KB
testcase_14 AC 119 ms
77,628 KB
testcase_15 AC 86 ms
76,672 KB
testcase_16 AC 96 ms
76,552 KB
testcase_17 AC 113 ms
77,536 KB
testcase_18 AC 124 ms
77,568 KB
testcase_19 AC 89 ms
76,600 KB
testcase_20 AC 89 ms
76,608 KB
testcase_21 AC 89 ms
76,520 KB
testcase_22 AC 123 ms
77,760 KB
testcase_23 AC 127 ms
77,840 KB
testcase_24 AC 119 ms
77,700 KB
testcase_25 AC 117 ms
77,908 KB
testcase_26 AC 123 ms
77,724 KB
testcase_27 AC 88 ms
76,640 KB
testcase_28 AC 90 ms
76,552 KB
testcase_29 AC 68 ms
71,588 KB
testcase_30 AC 69 ms
71,456 KB
testcase_31 AC 232 ms
81,408 KB
testcase_32 AC 290 ms
83,172 KB
testcase_33 AC 514 ms
91,824 KB
testcase_34 AC 717 ms
95,324 KB
testcase_35 AC 1,141 ms
106,768 KB
testcase_36 AC 672 ms
97,136 KB
testcase_37 AC 643 ms
96,300 KB
testcase_38 AC 685 ms
94,832 KB
testcase_39 AC 356 ms
85,940 KB
testcase_40 AC 431 ms
89,940 KB
testcase_41 AC 297 ms
83,040 KB
testcase_42 AC 940 ms
100,876 KB
testcase_43 AC 551 ms
95,640 KB
testcase_44 AC 921 ms
100,688 KB
testcase_45 AC 986 ms
105,200 KB
testcase_46 AC 232 ms
82,848 KB
testcase_47 AC 726 ms
94,828 KB
testcase_48 AC 262 ms
82,516 KB
testcase_49 AC 442 ms
87,748 KB
testcase_50 AC 1,036 ms
105,908 KB
testcase_51 AC 1,335 ms
109,992 KB
testcase_52 AC 1,320 ms
110,068 KB
testcase_53 AC 1,291 ms
109,608 KB
testcase_54 AC 1,316 ms
109,872 KB
testcase_55 AC 1,330 ms
109,868 KB
testcase_56 AC 288 ms
86,020 KB
testcase_57 AC 297 ms
85,960 KB
testcase_58 AC 784 ms
102,332 KB
testcase_59 AC 874 ms
105,336 KB
testcase_60 AC 521 ms
93,728 KB
testcase_61 AC 796 ms
103,060 KB
testcase_62 AC 785 ms
102,752 KB
testcase_63 AC 343 ms
87,500 KB
testcase_64 AC 539 ms
94,272 KB
testcase_65 AC 530 ms
92,828 KB
testcase_66 AC 525 ms
92,964 KB
testcase_67 AC 655 ms
97,712 KB
testcase_68 AC 537 ms
93,952 KB
testcase_69 AC 403 ms
88,500 KB
testcase_70 AC 424 ms
89,580 KB
testcase_71 AC 414 ms
89,736 KB
testcase_72 AC 570 ms
96,304 KB
testcase_73 AC 792 ms
104,760 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 = int(Li)
    Ri = int(Ri)
    
    if Ti=='Y':
        LRT.append((Li, Ri, 1))
    elif Ti=='K':
        LRT.append((Li, Ri, 2))
    elif Ti=='C':
        LRT.append((Li, Ri, 3))
        
lst = LazySegmentTree(N)

for i in range(M-1, -1, -1):
    Li, Ri, Ti = LRT[i]
    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==1:
        Y += 1
    elif v==2:
        K += 1
    elif v==3:
        C += 1

print(Y, K, C)
0