結果

問題 No.945 YKC饅頭
ユーザー tamatotamato
提出日時 2019-12-09 22:46:35
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 2,247 bytes
コンパイル時間 580 ms
コンパイル使用メモリ 85,724 KB
実行使用メモリ 160,000 KB
最終ジャッジ日時 2023-09-05 11:52:57
合計ジャッジ時間 39,528 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,276 KB
testcase_01 RE -
testcase_02 AC 87 ms
75,900 KB
testcase_03 AC 102 ms
77,488 KB
testcase_04 AC 79 ms
75,620 KB
testcase_05 AC 92 ms
76,288 KB
testcase_06 AC 103 ms
77,188 KB
testcase_07 AC 92 ms
76,116 KB
testcase_08 RE -
testcase_09 AC 90 ms
76,136 KB
testcase_10 AC 98 ms
76,180 KB
testcase_11 AC 87 ms
76,252 KB
testcase_12 RE -
testcase_13 WA -
testcase_14 AC 101 ms
77,260 KB
testcase_15 AC 75 ms
71,356 KB
testcase_16 RE -
testcase_17 AC 86 ms
76,176 KB
testcase_18 AC 94 ms
76,176 KB
testcase_19 RE -
testcase_20 AC 85 ms
75,840 KB
testcase_21 AC 80 ms
75,720 KB
testcase_22 AC 104 ms
77,440 KB
testcase_23 AC 106 ms
77,452 KB
testcase_24 AC 104 ms
77,252 KB
testcase_25 AC 107 ms
77,312 KB
testcase_26 AC 103 ms
77,164 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 AC 75 ms
71,204 KB
testcase_30 AC 74 ms
71,292 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 AC 965 ms
119,988 KB
testcase_35 AC 1,620 ms
150,812 KB
testcase_36 AC 753 ms
120,224 KB
testcase_37 WA -
testcase_38 AC 743 ms
112,140 KB
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 AC 1,194 ms
129,948 KB
testcase_43 WA -
testcase_44 AC 1,180 ms
139,292 KB
testcase_45 WA -
testcase_46 RE -
testcase_47 RE -
testcase_48 AC 241 ms
86,048 KB
testcase_49 RE -
testcase_50 AC 1,288 ms
132,568 KB
testcase_51 AC 1,887 ms
159,552 KB
testcase_52 AC 1,903 ms
159,712 KB
testcase_53 AC 1,929 ms
159,732 KB
testcase_54 AC 1,862 ms
159,744 KB
testcase_55 AC 1,895 ms
160,000 KB
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
testcase_61 RE -
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 RE -
testcase_69 RE -
testcase_70 RE -
testcase_71 RE -
testcase_72 RE -
testcase_73 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

    # i+1番目からR番目まで足すとt以上となるような最小のRを返す
    def bisect_plus(self, i, t):
        L = i
        R = self.size
        R_prev = R
        sum_i = self.sum(i)
        while True:
            range_sum = self.sum(R) - sum_i
            if range_sum < t:
                if R == self.size:
                    return self.size + 1
                L, R = R, R_prev
            else:
                R_prev = R
                R = (L + R + 1) // 2
                if R == R_prev:
                    return R

    # L番目からi-1番目まで足すとt以上となるような最小のLを返す
    def bisect_minus(self, i, t):
        L = 1
        R = i
        L_prev = L
        sum_i = self.sum(i - 1)
        while True:
            range_sum = sum_i - self.sum(L - 1)
            if range_sum < t:
                if L == 1:
                    return 0
                L, R = L_prev, L
            else:
                L_prev = L
                L = (L + R) // 2
                if L == L_prev:
                    return L

def main():
    N, M = map(int, input().split())
    q = []
    qy = [0] * (M+1)
    ans = [0] * 3
    bit = Bit(N)
    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))
    for i in range(1, N+1):
        q.append((i, 0, 0))

    q.sort(key=lambda x: x[0])
    for i, flg, j in q:
        if flg == 1:
            bit.add(j, 1)
        elif flg == -1:
            bit.add(j, -1)
        elif flg == 0:
            k = bit.bisect_plus(0, 1)
            if k == M+1:
                continue
            ans[qy[k]] += 1

    print(*ans)


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