結果

問題 No.59 鉄道の旅
ユーザー Ricky_ponRicky_pon
提出日時 2020-05-22 16:00:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 761 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 17,096 KB
最終ジャッジ日時 2024-04-15 06:21:32
合計ジャッジ時間 1,976 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
11,520 KB
testcase_01 AC 36 ms
11,520 KB
testcase_02 AC 36 ms
11,520 KB
testcase_03 AC 36 ms
11,520 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 55 ms
11,648 KB
testcase_12 AC 199 ms
12,528 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
権限があれば一括ダウンロードができます

ソースコード

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 = 100010
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