結果
問題 | No.618 labo-index |
ユーザー | maspy |
提出日時 | 2020-04-08 01:25:05 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,551 bytes |
コンパイル時間 | 1,694 ms |
コンパイル使用メモリ | 87,008 KB |
実行使用メモリ | 118,504 KB |
最終ジャッジ日時 | 2023-09-22 21:02:02 |
合計ジャッジ時間 | 11,511 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 76 ms
70,980 KB |
testcase_01 | AC | 83 ms
71,372 KB |
testcase_02 | AC | 72 ms
71,240 KB |
testcase_03 | AC | 72 ms
71,228 KB |
testcase_04 | AC | 112 ms
76,168 KB |
testcase_05 | AC | 124 ms
77,916 KB |
testcase_06 | AC | 72 ms
71,132 KB |
testcase_07 | AC | 81 ms
75,660 KB |
testcase_08 | AC | 85 ms
76,032 KB |
testcase_09 | AC | 94 ms
76,024 KB |
testcase_10 | AC | 98 ms
76,728 KB |
testcase_11 | AC | 92 ms
76,232 KB |
testcase_12 | WA | - |
testcase_13 | AC | 95 ms
76,304 KB |
testcase_14 | AC | 90 ms
76,084 KB |
testcase_15 | WA | - |
testcase_16 | AC | 110 ms
78,144 KB |
testcase_17 | WA | - |
testcase_18 | AC | 122 ms
77,768 KB |
testcase_19 | AC | 329 ms
102,556 KB |
testcase_20 | AC | 304 ms
102,708 KB |
testcase_21 | AC | 316 ms
102,544 KB |
testcase_22 | AC | 309 ms
102,668 KB |
testcase_23 | AC | 310 ms
102,532 KB |
testcase_24 | AC | 312 ms
102,680 KB |
testcase_25 | AC | 310 ms
102,696 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 303 ms
102,560 KB |
testcase_29 | AC | 310 ms
102,856 KB |
testcase_30 | AC | 318 ms
102,700 KB |
testcase_31 | AC | 311 ms
102,640 KB |
testcase_32 | AC | 316 ms
102,684 KB |
testcase_33 | AC | 304 ms
102,680 KB |
testcase_34 | AC | 327 ms
118,504 KB |
testcase_35 | AC | 323 ms
118,072 KB |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | AC | 71 ms
71,336 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): if full == 0: return 0 if nums[1] + base > full: return 0 data = bit.data size = bit.size x, sx = 0, 0 for i in range(bit.depth - 1, -1, -1): dx = (1 << i) if x + dx >= size: continue y = x + dx sy = sx + data[y] if y + 1 < len(nums) and full - sy >= nums[y + 1] + base: x, sx = y, sy cand = nums[x + 1] + base n = bit.get_sum(x + 1) if nums[x + 1] + 1 + base <= full - n: return full - n else: return cand 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))