結果
問題 | No.59 鉄道の旅 |
ユーザー |
![]() |
提出日時 | 2020-12-06 03:15:04 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 155 ms / 5,000 ms |
コード長 | 1,375 bytes |
コンパイル時間 | 415 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 92,604 KB |
最終ジャッジ日時 | 2024-09-16 20:53:13 |
合計ジャッジ時間 | 3,127 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 12 |
ソースコード
import syssys.setrecursionlimit(10**7)def I(): return int(sys.stdin.readline().rstrip())def MI(): return map(int,sys.stdin.readline().rstrip().split())def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))def LI2(): return list(map(int,sys.stdin.readline().rstrip()))def S(): return sys.stdin.readline().rstrip()def LS(): return list(sys.stdin.readline().rstrip().split())def LS2(): return list(sys.stdin.readline().rstrip())class BIT:def __init__(self,init_value):self.n = len(init_value)self.tree = [0]*(self.n+1)for i in range(1,self.n+1):x = init_value[i-1]while i <= self.n:self.tree[i] += xi += i & (-i)def update(self,i,x): # i(1-index)番目の値を+xwhile i <= self.n:self.tree[i] += xi += i & (-i)returndef query(self,i): # 1番目からi(1-index)番目までの和を返すres = 0while i > 0:res += self.tree[i]i -= i & (-i)return resN,K = MI()W = [I() for _ in range(N)]B = BIT([0]*1000001)for i in range(N):w = W[i]if w < 0:w = -wif B.query(w)-B.query(w-1) > 0:B.update(w,-1)else:if B.query(1000000)-B.query(w-1) < K:B.update(w,1)print(B.query(1000000))