結果

問題 No.59 鉄道の旅
ユーザー Ricky_ponRicky_pon
提出日時 2020-05-22 16:00:30
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 761 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 82,264 KB
実行使用メモリ 87,768 KB
最終ジャッジ日時 2024-04-15 06:22:06
合計ジャッジ時間 1,787 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
58,164 KB
testcase_01 AC 40 ms
59,092 KB
testcase_02 AC 39 ms
59,320 KB
testcase_03 AC 37 ms
58,584 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 51 ms
72,388 KB
testcase_12 AC 74 ms
87,768 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