結果

問題 No.945 YKC饅頭
ユーザー tamatotamato
提出日時 2020-04-01 10:54:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,151 ms / 2,000 ms
コード長 1,575 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 87,360 KB
実行使用メモリ 135,872 KB
最終ジャッジ日時 2023-09-08 13:26:33
合計ジャッジ時間 31,622 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,424 KB
testcase_01 AC 72 ms
71,332 KB
testcase_02 AC 79 ms
75,848 KB
testcase_03 AC 90 ms
76,188 KB
testcase_04 AC 76 ms
75,964 KB
testcase_05 AC 82 ms
75,860 KB
testcase_06 AC 85 ms
76,240 KB
testcase_07 AC 80 ms
75,832 KB
testcase_08 AC 77 ms
75,284 KB
testcase_09 AC 79 ms
75,964 KB
testcase_10 AC 87 ms
76,188 KB
testcase_11 AC 81 ms
75,924 KB
testcase_12 AC 84 ms
76,088 KB
testcase_13 AC 91 ms
76,384 KB
testcase_14 AC 86 ms
76,324 KB
testcase_15 AC 78 ms
75,488 KB
testcase_16 AC 79 ms
75,752 KB
testcase_17 AC 84 ms
76,100 KB
testcase_18 AC 86 ms
76,312 KB
testcase_19 AC 80 ms
75,588 KB
testcase_20 AC 79 ms
75,844 KB
testcase_21 AC 78 ms
75,648 KB
testcase_22 AC 91 ms
76,072 KB
testcase_23 AC 93 ms
76,324 KB
testcase_24 AC 92 ms
76,184 KB
testcase_25 AC 89 ms
76,352 KB
testcase_26 AC 91 ms
76,248 KB
testcase_27 AC 74 ms
71,352 KB
testcase_28 AC 75 ms
71,088 KB
testcase_29 AC 73 ms
71,408 KB
testcase_30 AC 74 ms
71,364 KB
testcase_31 AC 133 ms
79,340 KB
testcase_32 AC 112 ms
77,548 KB
testcase_33 AC 307 ms
88,312 KB
testcase_34 AC 577 ms
104,868 KB
testcase_35 AC 918 ms
117,420 KB
testcase_36 AC 815 ms
121,676 KB
testcase_37 AC 732 ms
112,404 KB
testcase_38 AC 659 ms
109,584 KB
testcase_39 AC 208 ms
83,224 KB
testcase_40 AC 178 ms
81,088 KB
testcase_41 AC 127 ms
78,692 KB
testcase_42 AC 878 ms
116,012 KB
testcase_43 AC 694 ms
113,228 KB
testcase_44 AC 681 ms
108,016 KB
testcase_45 AC 1,029 ms
135,872 KB
testcase_46 AC 104 ms
77,324 KB
testcase_47 AC 585 ms
104,036 KB
testcase_48 AC 190 ms
84,556 KB
testcase_49 AC 273 ms
89,344 KB
testcase_50 AC 1,080 ms
134,392 KB
testcase_51 AC 1,151 ms
126,720 KB
testcase_52 AC 1,113 ms
126,716 KB
testcase_53 AC 1,082 ms
126,632 KB
testcase_54 AC 1,077 ms
126,608 KB
testcase_55 AC 1,096 ms
126,792 KB
testcase_56 AC 106 ms
76,680 KB
testcase_57 AC 109 ms
77,052 KB
testcase_58 AC 697 ms
110,384 KB
testcase_59 AC 848 ms
116,424 KB
testcase_60 AC 370 ms
91,372 KB
testcase_61 AC 747 ms
112,244 KB
testcase_62 AC 725 ms
111,768 KB
testcase_63 AC 142 ms
78,016 KB
testcase_64 AC 403 ms
92,968 KB
testcase_65 AC 340 ms
92,184 KB
testcase_66 AC 321 ms
90,464 KB
testcase_67 AC 564 ms
101,532 KB
testcase_68 AC 373 ms
92,136 KB
testcase_69 AC 212 ms
82,032 KB
testcase_70 AC 227 ms
83,500 KB
testcase_71 AC 225 ms
83,620 KB
testcase_72 AC 469 ms
97,616 KB
testcase_73 AC 853 ms
122,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.readline

    class Bit:
        def __init__(self, n):
            self.size = n
            self.tree = [0] * (n + 1)

        def sum(self, i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x):
            while i <= self.size:
                self.tree[i] += x
                i += i & -i

        def lower_bound(self, w):
            if w <= 0:
                return 0
            x = 0
            k = 1 << (self.size.bit_length() - 1)
            while k:
                if x + k <= self.size and self.tree[x + k] < w:
                    w -= self.tree[x + k]
                    x += k
                k >>= 1
            return x+1

    N, M = map(int, input().split())
    q = []
    qy = [0] * (M+1)
    ans = [0] * 3
    bit = Bit(M)
    for i in range(1, M+1):
        s, t, y = input().split()
        s = int(s)
        t = int(t)
        if y == 'K':
            qy[i] = 1
        elif y == 'C':
            qy[i] = 2
        q.append((s, 1, i))
        if t+1 <= N:
            q.append((t+1, -1, i))

    q.sort(key=lambda x: x[0])
    i = 1
    for t, flg, j in q:
        while i < t:
            k = bit.lower_bound(1)
            if k != M + 1:
                ans[qy[k]] += 1
            i += 1
        bit.add(j, flg)

    while i < N+1:
        k = bit.lower_bound(1)
        if k != M + 1:
            ans[qy[k]] += 1
        i += 1

    print(*ans)


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