結果

問題 No.945 YKC饅頭
ユーザー 👑 tamatotamato
提出日時 2019-12-09 22:47:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,898 ms / 2,000 ms
コード長 2,247 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 160,436 KB
最終ジャッジ日時 2023-09-05 11:56:07
合計ジャッジ時間 47,728 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,276 KB
testcase_01 AC 74 ms
71,296 KB
testcase_02 AC 86 ms
76,012 KB
testcase_03 AC 101 ms
77,196 KB
testcase_04 AC 84 ms
75,800 KB
testcase_05 AC 96 ms
76,372 KB
testcase_06 AC 103 ms
77,200 KB
testcase_07 AC 95 ms
76,384 KB
testcase_08 AC 85 ms
75,972 KB
testcase_09 AC 91 ms
76,268 KB
testcase_10 AC 96 ms
76,308 KB
testcase_11 AC 88 ms
76,204 KB
testcase_12 AC 95 ms
76,328 KB
testcase_13 AC 102 ms
77,468 KB
testcase_14 AC 102 ms
77,420 KB
testcase_15 AC 83 ms
75,648 KB
testcase_16 AC 86 ms
75,864 KB
testcase_17 AC 92 ms
76,152 KB
testcase_18 AC 93 ms
76,284 KB
testcase_19 AC 89 ms
75,980 KB
testcase_20 AC 87 ms
76,024 KB
testcase_21 AC 82 ms
75,780 KB
testcase_22 AC 103 ms
77,484 KB
testcase_23 AC 105 ms
77,476 KB
testcase_24 AC 106 ms
77,232 KB
testcase_25 AC 107 ms
77,244 KB
testcase_26 AC 105 ms
77,260 KB
testcase_27 AC 79 ms
75,060 KB
testcase_28 AC 78 ms
74,904 KB
testcase_29 AC 76 ms
71,492 KB
testcase_30 AC 74 ms
71,220 KB
testcase_31 AC 211 ms
84,968 KB
testcase_32 AC 320 ms
95,828 KB
testcase_33 AC 607 ms
105,664 KB
testcase_34 AC 956 ms
120,084 KB
testcase_35 AC 1,607 ms
150,604 KB
testcase_36 AC 895 ms
121,176 KB
testcase_37 AC 862 ms
116,140 KB
testcase_38 AC 833 ms
112,448 KB
testcase_39 AC 401 ms
97,160 KB
testcase_40 AC 508 ms
102,972 KB
testcase_41 AC 319 ms
89,312 KB
testcase_42 AC 1,258 ms
130,584 KB
testcase_43 AC 754 ms
116,348 KB
testcase_44 AC 1,191 ms
139,040 KB
testcase_45 AC 1,365 ms
137,540 KB
testcase_46 AC 224 ms
86,732 KB
testcase_47 AC 970 ms
122,724 KB
testcase_48 AC 240 ms
86,564 KB
testcase_49 AC 541 ms
102,480 KB
testcase_50 AC 1,409 ms
133,300 KB
testcase_51 AC 1,876 ms
159,436 KB
testcase_52 AC 1,898 ms
159,688 KB
testcase_53 AC 1,846 ms
159,640 KB
testcase_54 AC 1,857 ms
159,748 KB
testcase_55 AC 1,830 ms
160,436 KB
testcase_56 AC 155 ms
103,936 KB
testcase_57 AC 160 ms
103,976 KB
testcase_58 AC 1,484 ms
138,884 KB
testcase_59 AC 1,661 ms
151,864 KB
testcase_60 AC 930 ms
125,288 KB
testcase_61 AC 1,506 ms
134,548 KB
testcase_62 AC 1,494 ms
136,436 KB
testcase_63 AC 210 ms
98,380 KB
testcase_64 AC 956 ms
122,592 KB
testcase_65 AC 829 ms
115,464 KB
testcase_66 AC 780 ms
113,644 KB
testcase_67 AC 1,259 ms
130,232 KB
testcase_68 AC 949 ms
124,588 KB
testcase_69 AC 471 ms
110,644 KB
testcase_70 AC 534 ms
116,456 KB
testcase_71 AC 565 ms
116,884 KB
testcase_72 AC 1,052 ms
119,468 KB
testcase_73 AC 1,603 ms
152,256 KB
権限があれば一括ダウンロードができます

ソースコード

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(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))
    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