結果

問題 No.945 YKC饅頭
ユーザー 👑 rin204rin204
提出日時 2022-02-11 21:04:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 870 ms / 2,000 ms
コード長 1,539 bytes
コンパイル時間 1,420 ms
コンパイル使用メモリ 87,220 KB
実行使用メモリ 136,504 KB
最終ジャッジ日時 2023-09-09 23:51:53
合計ジャッジ時間 34,621 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,068 KB
testcase_01 AC 75 ms
71,348 KB
testcase_02 AC 83 ms
75,412 KB
testcase_03 AC 117 ms
77,468 KB
testcase_04 AC 82 ms
75,660 KB
testcase_05 AC 86 ms
75,556 KB
testcase_06 AC 98 ms
75,904 KB
testcase_07 AC 93 ms
76,072 KB
testcase_08 AC 78 ms
71,388 KB
testcase_09 AC 95 ms
75,900 KB
testcase_10 AC 97 ms
75,772 KB
testcase_11 AC 90 ms
75,928 KB
testcase_12 AC 91 ms
75,964 KB
testcase_13 AC 112 ms
77,676 KB
testcase_14 AC 110 ms
77,400 KB
testcase_15 AC 92 ms
75,920 KB
testcase_16 AC 83 ms
75,556 KB
testcase_17 AC 115 ms
77,232 KB
testcase_18 AC 100 ms
75,936 KB
testcase_19 AC 76 ms
71,484 KB
testcase_20 AC 82 ms
76,056 KB
testcase_21 AC 86 ms
75,796 KB
testcase_22 AC 120 ms
77,424 KB
testcase_23 AC 119 ms
77,596 KB
testcase_24 AC 116 ms
77,568 KB
testcase_25 AC 119 ms
77,640 KB
testcase_26 AC 116 ms
77,732 KB
testcase_27 AC 74 ms
71,188 KB
testcase_28 AC 74 ms
71,068 KB
testcase_29 AC 73 ms
71,264 KB
testcase_30 AC 71 ms
71,392 KB
testcase_31 AC 212 ms
83,280 KB
testcase_32 AC 169 ms
87,956 KB
testcase_33 AC 359 ms
97,424 KB
testcase_34 AC 489 ms
105,912 KB
testcase_35 AC 741 ms
125,600 KB
testcase_36 AC 530 ms
106,140 KB
testcase_37 AC 495 ms
102,752 KB
testcase_38 AC 483 ms
102,504 KB
testcase_39 AC 298 ms
91,568 KB
testcase_40 AC 270 ms
92,916 KB
testcase_41 AC 189 ms
87,204 KB
testcase_42 AC 666 ms
114,900 KB
testcase_43 AC 460 ms
101,016 KB
testcase_44 AC 564 ms
113,792 KB
testcase_45 AC 665 ms
117,804 KB
testcase_46 AC 156 ms
84,444 KB
testcase_47 AC 481 ms
107,328 KB
testcase_48 AC 251 ms
83,760 KB
testcase_49 AC 324 ms
96,780 KB
testcase_50 AC 702 ms
122,116 KB
testcase_51 AC 821 ms
133,316 KB
testcase_52 AC 823 ms
133,540 KB
testcase_53 AC 801 ms
132,824 KB
testcase_54 AC 833 ms
135,200 KB
testcase_55 AC 837 ms
136,504 KB
testcase_56 AC 129 ms
91,216 KB
testcase_57 AC 114 ms
91,268 KB
testcase_58 AC 793 ms
114,752 KB
testcase_59 AC 859 ms
118,584 KB
testcase_60 AC 547 ms
104,544 KB
testcase_61 AC 753 ms
115,512 KB
testcase_62 AC 870 ms
116,660 KB
testcase_63 AC 144 ms
91,948 KB
testcase_64 AC 683 ms
106,892 KB
testcase_65 AC 595 ms
104,564 KB
testcase_66 AC 537 ms
103,668 KB
testcase_67 AC 656 ms
110,744 KB
testcase_68 AC 649 ms
106,992 KB
testcase_69 AC 307 ms
96,992 KB
testcase_70 AC 382 ms
98,320 KB
testcase_71 AC 374 ms
99,084 KB
testcase_72 AC 812 ms
111,080 KB
testcase_73 AC 858 ms
118,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

class Heapq:
    def __init__(self, lst = [], reverse = False):
        if reverse:
            self.pm = -1
            self.hq = [-l for l in lst]
        else:
            self.pm = 1
            self.hq = lst.copy()
        heapq.heapify(self.hq)
        self.tot = sum(lst)
        self.rm = []
        self.length = len(lst)
            
    def push(self, x):
        self.length += 1
        heapq.heappush(self.hq, x * self.pm)
        self.tot += x
    
    def pop(self):
        self.length -= 1
        ret = heapq.heappop(self.hq)
        self.tot -= self.pm * ret
        self.delete()
        return self.pm * ret
    
    def top(self):
        return self.pm * self.hq[0]
    
    def remove(self, x): # 存在しないものを消そうとするとバグる
        self.length -= 1
        self.tot -= x
        heapq.heappush(self.rm, self.pm * x)
        self.delete()
            
    def delete(self):
        while self.rm and self.rm[0] == self.hq[0]:
            heapq.heappop(self.rm)
            heapq.heappop(self.hq)

n, m = map(int, input().split())
add = [[] for _ in range(n)]
rem = [[] for _ in range(n)]
T = [""] * m
for i in range(m):
    l, r, t = input().split()
    T[i] = t
    add[int(l) - 1].append(i)
    rem[int(r) - 1].append(i)
    
ans = {"Y":0, "K":0, "C":0}
hq = Heapq()
for i in range(n):
    for j in add[i]:
        hq.push(j)
    if hq.length > 0:
        t = T[hq.top()]
        ans[t] += 1
    for j in rem[i]:
        hq.remove(j)
print(ans["Y"], ans["K"], ans["C"])

0