結果
問題 | No.59 鉄道の旅 |
ユーザー |
![]() |
提出日時 | 2020-01-09 12:06:17 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 573 ms / 5,000 ms |
コード長 | 1,422 bytes |
コンパイル時間 | 158 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 89,088 KB |
最終ジャッジ日時 | 2024-11-23 03:47:03 |
合計ジャッジ時間 | 4,147 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 12 |
ソースコード
import syssys.setrecursionlimit(10 ** 6)from bisect import *from collections import *from heapq import *int1 = lambda x: int(x) - 1p2D = lambda x: print(*x, sep="\n")def II(): return int(sys.stdin.readline())def MI(): return map(int, sys.stdin.readline().split())def MI1(): return map(int1, sys.stdin.readline().split())def MF(): return map(float, sys.stdin.readline().split())def LI(): return list(map(int, sys.stdin.readline().split()))def LI1(): return list(map(int1, sys.stdin.readline().split()))def LF(): return list(map(float, sys.stdin.readline().split()))def LLI(rows_number): return [LI() for _ in range(rows_number)]dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]class BitSum:def __init__(self, n):self.n = n + 3self.table = [0] * (self.n + 1)def update(self, i, x):i += 1while i <= self.n:self.table[i] += xi += i & -idef sum(self, i):i += 1res = 0while i > 0:res += self.table[i]i -= i & -ireturn resdef main():n,k=MI()bit=BitSum(10000005)cnt=0for _ in range(n):w=II()if w>0:if cnt-bit.sum(w-1)<k:bit.update(w,1)cnt+=1else:w=-wif bit.sum(w)-bit.sum(w-1):bit.update(w,-1)cnt-=1print(cnt)main()