結果

問題 No.59 鉄道の旅
ユーザー Ricky_ponRicky_pon
提出日時 2020-05-22 16:01:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 622 ms / 5,000 ms
コード長 762 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 24,908 KB
最終ジャッジ日時 2024-04-15 06:24:34
合計ジャッジ時間 3,820 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
18,688 KB
testcase_01 AC 79 ms
18,560 KB
testcase_02 AC 78 ms
18,560 KB
testcase_03 AC 76 ms
18,560 KB
testcase_04 AC 519 ms
24,356 KB
testcase_05 AC 76 ms
18,560 KB
testcase_06 AC 75 ms
18,560 KB
testcase_07 AC 75 ms
18,560 KB
testcase_08 AC 128 ms
19,072 KB
testcase_09 AC 123 ms
19,072 KB
testcase_10 AC 127 ms
19,200 KB
testcase_11 AC 97 ms
18,688 KB
testcase_12 AC 250 ms
19,560 KB
testcase_13 AC 572 ms
24,908 KB
testcase_14 AC 622 ms
24,904 KB
testcase_15 AC 78 ms
18,560 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