結果

問題 No.59 鉄道の旅
ユーザー Ricky_ponRicky_pon
提出日時 2020-05-22 16:02:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 116 ms / 5,000 ms
コード長 762 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 82,380 KB
実行使用メモリ 96,000 KB
最終ジャッジ日時 2024-04-15 06:24:56
合計ジャッジ時間 1,997 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
65,412 KB
testcase_01 AC 42 ms
66,452 KB
testcase_02 AC 45 ms
66,124 KB
testcase_03 AC 44 ms
66,484 KB
testcase_04 AC 116 ms
94,348 KB
testcase_05 AC 44 ms
66,604 KB
testcase_06 AC 48 ms
67,752 KB
testcase_07 AC 43 ms
66,740 KB
testcase_08 AC 63 ms
84,344 KB
testcase_09 AC 69 ms
84,168 KB
testcase_10 AC 69 ms
84,048 KB
testcase_11 AC 54 ms
77,232 KB
testcase_12 AC 77 ms
93,760 KB
testcase_13 AC 107 ms
96,000 KB
testcase_14 AC 103 ms
95,332 KB
testcase_15 AC 42 ms
65,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

class BinaryIndexedTree():
    def __init__(self, n):
        self.node = [0 for _ in range(n+1)]

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

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

n, K = map(int, readline().split())
w = map(int, read().split())
MAX = 1000010
bit = BinaryIndexedTree(MAX)
for x in w:
    if x > 0:
        if bit.sum(MAX) - bit.sum(x-1) < K:
            bit.add(x, 1)
    else:
        x = -x
        if bit.sum(x) - bit.sum(x-1) >= 1:
            bit.add(x, -1)
print(bit.sum(MAX))
0