結果
問題 | No.59 鉄道の旅 |
ユーザー | maspy |
提出日時 | 2020-03-17 16:22:53 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 150 ms / 5,000 ms |
コード長 | 1,788 bytes |
コンパイル時間 | 473 ms |
コンパイル使用メモリ | 87,248 KB |
実行使用メモリ | 108,472 KB |
最終ジャッジ日時 | 2023-08-20 18:50:52 |
合計ジャッジ時間 | 3,160 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 87 ms
90,952 KB |
testcase_01 | AC | 87 ms
91,108 KB |
testcase_02 | AC | 93 ms
90,920 KB |
testcase_03 | AC | 87 ms
91,100 KB |
testcase_04 | AC | 150 ms
106,520 KB |
testcase_05 | AC | 88 ms
91,120 KB |
testcase_06 | AC | 88 ms
91,464 KB |
testcase_07 | AC | 88 ms
91,012 KB |
testcase_08 | AC | 106 ms
92,552 KB |
testcase_09 | AC | 109 ms
92,672 KB |
testcase_10 | AC | 112 ms
92,752 KB |
testcase_11 | AC | 97 ms
91,832 KB |
testcase_12 | AC | 115 ms
107,068 KB |
testcase_13 | AC | 139 ms
108,472 KB |
testcase_14 | AC | 142 ms
108,320 KB |
testcase_15 | AC | 87 ms
91,248 KB |
ソースコード
#!/usr/bin/env python3.8 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% # import numpy as np # from numba import njit # %% class BinaryIndexedTree(): def __init__(self, seq): self.size = len(seq) self.depth = self.size.bit_length() self.build(seq) def build(self, seq): data = seq size = self.size for i, x in enumerate(data): j = i + (i & (-i)) if j < size: data[j] += data[i] self.data = data def __repr__(self): return self.data.__repr__() def get_sum(self, i): data = self.data s = 0 while i: s += data[i] i -= i & -i return s def add(self, i, x): data = self.data size = self.size while i < size: data[i] += x i += i & -i def find_kth_element(self, k): data = self.data; size = self.size x, sx = 0, 0 dx = 1 << (self.depth) for i in range(self.depth - 1, -1, -1): dx = (1 << i) if x + dx >= size: continue y = x + dx sy = sx + data[y] if sy < k: x, sx = y, sy return x + 1 # %% U = 10 ** 6 + 10 N, K, *W = map(int, read().split()) bit = BinaryIndexedTree([0] * U) data_raw = [0] * U total = 0 for w in W: if w < 0: w = -w if not data_raw[w]: continue data_raw[w] -= 1 total -= 1 bit.add(w, -1) else: smaller = bit.get_sum(w - 1) if total - smaller >= K: continue data_raw[w] += 1 bit.add(w, 1) total += 1 print(total)