結果
| 問題 |
No.59 鉄道の旅
|
| コンテスト | |
| ユーザー |
tnodino
|
| 提出日時 | 2022-02-26 20:27:05 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 721 ms / 5,000 ms |
| コード長 | 691 bytes |
| コンパイル時間 | 147 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 18,560 KB |
| 最終ジャッジ日時 | 2024-07-04 17:00:37 |
| 合計ジャッジ時間 | 4,261 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 12 |
ソースコード
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):
while i <= self.sz:
self.bit[i] += x
i += i & -i
INF = 10**6
N,K = map(int,input().split())
BIT = BinaryIndexedTree(INF)
for _ in range(N):
W = int(input())
if W < 0:
W = abs(W)
if BIT.Sum(W) - BIT.Sum(W-1) > 0:
BIT.Add(W, -1)
else:
if BIT.Sum(INF) - BIT.Sum(W-1) < K:
BIT.Add(W, 1)
print(BIT.Sum(INF))
tnodino