結果

問題 No.59 鉄道の旅
ユーザー tnodinotnodino
提出日時 2022-02-26 20:20:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 756 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 10,940 KB
実行使用メモリ 26,824 KB
最終ジャッジ日時 2023-09-17 23:38:24
合計ジャッジ時間 3,573 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
16,112 KB
testcase_01 AC 34 ms
16,212 KB
testcase_02 AC 34 ms
16,140 KB
testcase_03 AC 34 ms
16,184 KB
testcase_04 AC 466 ms
21,732 KB
testcase_05 WA -
testcase_06 AC 35 ms
16,180 KB
testcase_07 WA -
testcase_08 AC 97 ms
16,992 KB
testcase_09 AC 78 ms
16,928 KB
testcase_10 WA -
testcase_11 AC 66 ms
16,248 KB
testcase_12 AC 338 ms
16,204 KB
testcase_13 AC 479 ms
21,676 KB
testcase_14 WA -
testcase_15 AC 34 ms
16,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
class BinaryIndexedTree:
    def __init__(self, N):
        self.sz = N
        self.bit = [0] * (N + 1)

    def Sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s

    def Add(self, i, x):
        i += 1
        while i <= self.sz:
            self.bit[i] += x
            i += i & -i

INF = 10**6
N,K = map(int,input().split())
BIT = BinaryIndexedTree(INF)
cnt = defaultdict(int)
for _ in range(N):
    W = int(input())
    if W < 0:
        W = abs(W)
        if cnt[W] > 0:
            BIT.Add(W, -1)
            cnt[W] -= 1
    else:
        if BIT.Sum(INF) - BIT.Sum(W) < K:
            BIT.Add(W, 1)
            cnt[W] += 1
print(BIT.Sum(INF))
0