結果

問題 No.59 鉄道の旅
ユーザー Ricky_ponRicky_pon
提出日時 2020-05-22 16:02:12
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 151 ms / 5,000 ms
コード長 762 bytes
コンパイル時間 423 ms
コンパイル使用メモリ 87,156 KB
実行使用メモリ 96,912 KB
最終ジャッジ日時 2023-07-27 19:37:31
合計ジャッジ時間 2,889 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
82,968 KB
testcase_01 AC 81 ms
82,992 KB
testcase_02 AC 80 ms
83,060 KB
testcase_03 AC 80 ms
83,040 KB
testcase_04 AC 151 ms
95,472 KB
testcase_05 AC 79 ms
83,660 KB
testcase_06 AC 82 ms
83,872 KB
testcase_07 AC 79 ms
83,656 KB
testcase_08 AC 99 ms
85,184 KB
testcase_09 AC 105 ms
85,320 KB
testcase_10 AC 106 ms
85,744 KB
testcase_11 AC 91 ms
84,476 KB
testcase_12 AC 112 ms
94,824 KB
testcase_13 AC 146 ms
96,912 KB
testcase_14 AC 143 ms
96,804 KB
testcase_15 AC 78 ms
82,952 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