結果

問題 No.59 鉄道の旅
ユーザー convexineqconvexineq
提出日時 2020-12-06 05:13:58
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 161 ms / 5,000 ms
コード長 1,101 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 81,616 KB
実行使用メモリ 91,704 KB
最終ジャッジ日時 2023-10-17 06:07:54
合計ジャッジ時間 2,842 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
69,028 KB
testcase_01 AC 45 ms
69,028 KB
testcase_02 AC 45 ms
69,028 KB
testcase_03 AC 46 ms
69,028 KB
testcase_04 AC 161 ms
91,504 KB
testcase_05 AC 50 ms
74,996 KB
testcase_06 AC 53 ms
75,064 KB
testcase_07 AC 46 ms
69,028 KB
testcase_08 AC 95 ms
91,472 KB
testcase_09 AC 97 ms
91,704 KB
testcase_10 AC 99 ms
91,504 KB
testcase_11 AC 89 ms
91,440 KB
testcase_12 AC 142 ms
91,444 KB
testcase_13 AC 143 ms
91,508 KB
testcase_14 AC 152 ms
91,472 KB
testcase_15 AC 45 ms
69,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT: #0-indexed
    __slots__ = ["size", "tree","depth","n0"]
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
        self.depth = n.bit_length()
        self.n0 = 1<<self.depth

    def get_sum(self, i): #a_0 + ... + a_{i} #閉区間
        s = 0; i += 1
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def range_sum(self,l,r): #a_l + ... + a_r 閉区間
        return self.get_sum(r) - self.get_sum(l-1) 

    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def range_sum_larger(self,l): #a_l + ... (端まで)
        return self.get_sum(self.size-1) - (self.get_sum(l-1) if l else 0)
        

n,k = map(int,input().split())
bit = BIT(10**6+1)
num = [0]*(10**6+1)
for _ in range(n):
    w = int(input())
    if w < 0:
        w = -w
        if num[w]:
            num[w] -= 1
            bit.add(w,-1)
    else:
        if bit.range_sum_larger(w) < k:
            num[w] += 1
            bit.add(w,1)
print(bit.range_sum_larger(0))
0