結果
問題 | No.618 labo-index |
ユーザー | maspy |
提出日時 | 2020-04-08 01:31:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 732 ms / 6,000 ms |
コード長 | 2,240 bytes |
コンパイル時間 | 227 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 124,544 KB |
最終ジャッジ日時 | 2024-07-08 11:44:41 |
合計ジャッジ時間 | 12,459 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
52,224 KB |
testcase_01 | AC | 37 ms
52,352 KB |
testcase_02 | AC | 34 ms
52,224 KB |
testcase_03 | AC | 34 ms
51,968 KB |
testcase_04 | AC | 69 ms
73,600 KB |
testcase_05 | AC | 90 ms
76,416 KB |
testcase_06 | AC | 41 ms
58,368 KB |
testcase_07 | AC | 47 ms
60,800 KB |
testcase_08 | AC | 54 ms
64,896 KB |
testcase_09 | AC | 63 ms
68,736 KB |
testcase_10 | AC | 78 ms
76,032 KB |
testcase_11 | AC | 63 ms
69,120 KB |
testcase_12 | AC | 59 ms
67,456 KB |
testcase_13 | AC | 69 ms
71,936 KB |
testcase_14 | AC | 64 ms
68,992 KB |
testcase_15 | AC | 71 ms
72,576 KB |
testcase_16 | AC | 86 ms
76,288 KB |
testcase_17 | AC | 57 ms
66,304 KB |
testcase_18 | AC | 102 ms
77,312 KB |
testcase_19 | AC | 422 ms
103,040 KB |
testcase_20 | AC | 490 ms
102,912 KB |
testcase_21 | AC | 434 ms
102,400 KB |
testcase_22 | AC | 436 ms
102,528 KB |
testcase_23 | AC | 450 ms
103,040 KB |
testcase_24 | AC | 439 ms
102,912 KB |
testcase_25 | AC | 472 ms
102,912 KB |
testcase_26 | AC | 475 ms
102,656 KB |
testcase_27 | AC | 474 ms
102,784 KB |
testcase_28 | AC | 480 ms
102,400 KB |
testcase_29 | AC | 467 ms
103,168 KB |
testcase_30 | AC | 442 ms
102,656 KB |
testcase_31 | AC | 489 ms
102,700 KB |
testcase_32 | AC | 485 ms
102,784 KB |
testcase_33 | AC | 496 ms
102,784 KB |
testcase_34 | AC | 732 ms
124,544 KB |
testcase_35 | AC | 717 ms
123,392 KB |
testcase_36 | AC | 330 ms
104,576 KB |
testcase_37 | AC | 561 ms
111,872 KB |
testcase_38 | AC | 39 ms
52,096 KB |
ソースコード
#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines 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 Q = int(readline()) m = map(int, read().split()) query = tuple(zip(m, m)) nums = [] base = 0 for t, x in query: if t == 1: nums.append(x - base) elif t == 2: continue else: base += x INF = 10 ** 18 nums.append(-INF) nums.append(INF) nums = sorted(set(nums)) num_rank = {x: i for i, x in enumerate(nums)} def solve(bit, nums, full, base): left = 0 right = full + 1 while left + 1 < right: k = (left + right) // 2 if base + nums[bit.find_kth_element(full + 1 - k)] >= k: left = k else: right = k return left bit = BinaryIndexedTree([0] * (len(nums))) base = 0 member = [] full = 0 for t, x in query: if t == 1: r = num_rank[x - base] member.append(r) bit.add(r, 1) full += 1 elif t == 2: r = member[x - 1] bit.add(r, -1) full -= 1 else: base += x print(solve(bit, nums, full, base))