結果

問題 No.945 YKC饅頭
ユーザー mkawa2mkawa2
提出日時 2019-12-12 09:20:54
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,943 bytes
コンパイル時間 414 ms
コンパイル使用メモリ 82,828 KB
実行使用メモリ 133,420 KB
最終ジャッジ日時 2024-06-24 18:06:14
合計ジャッジ時間 45,692 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 70 TLE * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

class SegmentTree:
    def __init__(self, aa):
        width = 1 << ((len(aa) - 1).bit_length())
        tree = [-1] * (width * 2 - 1)
        lazy = [-1] * (width * 2 - 1)
        tree[width - 1:] = aa
        self.width = width
        self.tree = tree
        self.lazy = lazy

    def _prop(self, u):
        if self.lazy[u] == -1: return
        value = self.tree[u] = self.lazy[u]
        self.lazy[u] = -1
        if u < self.width - 1:
            self.lazy[u * 2 + 1] = self.lazy[u * 2 + 2] = value

    def update(self, l, r, a, u=0, uL=0, uR=-1):
        if uR == -1: uR = self.width
        self._prop(u)
        if r <= uL or uR <= l:
            return
        elif l <= uL and uR <= r:
            self.lazy[u] = a
            return
        uM = (uL + uR) // 2
        self.update(l, r, a, u * 2 + 1, uL, uM)
        self.update(l, r, a, u * 2 + 2, uM, uR)

    def get_elements(self):
        for u in range(self.width - 1):
            self._prop(u)
        for u in range(self.width - 1, self.width * 2 - 1):
            if self.lazy[u] == -1: continue
            self.tree[u] = self.lazy[u]
        return self.tree[self.width - 1:]

def main():
    n, m = MI()
    lrt = [input().split() for _ in range(m)]
    aa = [-1] * n
    st = SegmentTree(aa)
    for l, r, t in lrt[::-1]:
        l, r = int1(l), int(r)
        if t == "Y":
            mark = 1
        elif t == "K":
            mark = 2
        else:
            mark = 3
        st.update(l, r, mark)
    aa = st.get_elements()
    cnt = defaultdict(int)
    for a in aa:
        cnt[a] += 1
    print(cnt[1], cnt[2], cnt[3])

main()
0