結果
問題 | No.618 labo-index |
ユーザー | n_knuu |
提出日時 | 2017-11-27 03:10:24 |
言語 | PyPy2 (7.3.15) |
結果 |
AC
|
実行時間 | 2,539 ms / 6,000 ms |
コード長 | 3,082 bytes |
コンパイル時間 | 306 ms |
コンパイル使用メモリ | 76,976 KB |
実行使用メモリ | 111,080 KB |
最終ジャッジ日時 | 2024-11-27 12:04:39 |
合計ジャッジ時間 | 30,520 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 82 ms
75,904 KB |
testcase_01 | AC | 78 ms
75,696 KB |
testcase_02 | AC | 79 ms
75,904 KB |
testcase_03 | AC | 77 ms
75,792 KB |
testcase_04 | AC | 129 ms
79,360 KB |
testcase_05 | AC | 143 ms
80,000 KB |
testcase_06 | AC | 87 ms
77,724 KB |
testcase_07 | AC | 93 ms
77,820 KB |
testcase_08 | AC | 103 ms
78,464 KB |
testcase_09 | AC | 117 ms
79,104 KB |
testcase_10 | AC | 130 ms
79,252 KB |
testcase_11 | AC | 110 ms
78,456 KB |
testcase_12 | AC | 109 ms
78,336 KB |
testcase_13 | AC | 122 ms
79,360 KB |
testcase_14 | AC | 109 ms
78,592 KB |
testcase_15 | AC | 125 ms
79,104 KB |
testcase_16 | AC | 140 ms
79,896 KB |
testcase_17 | AC | 104 ms
78,656 KB |
testcase_18 | AC | 160 ms
80,356 KB |
testcase_19 | AC | 1,061 ms
102,056 KB |
testcase_20 | AC | 1,334 ms
101,932 KB |
testcase_21 | AC | 1,106 ms
101,812 KB |
testcase_22 | AC | 1,170 ms
102,392 KB |
testcase_23 | AC | 1,252 ms
102,272 KB |
testcase_24 | AC | 1,123 ms
102,200 KB |
testcase_25 | AC | 1,203 ms
101,684 KB |
testcase_26 | AC | 1,149 ms
101,884 KB |
testcase_27 | AC | 1,194 ms
101,972 KB |
testcase_28 | AC | 1,018 ms
101,908 KB |
testcase_29 | AC | 1,228 ms
102,188 KB |
testcase_30 | AC | 1,006 ms
102,532 KB |
testcase_31 | AC | 1,117 ms
101,720 KB |
testcase_32 | AC | 1,173 ms
102,152 KB |
testcase_33 | AC | 1,115 ms
101,676 KB |
testcase_34 | AC | 2,493 ms
111,080 KB |
testcase_35 | AC | 2,539 ms
110,328 KB |
testcase_36 | AC | 1,945 ms
103,772 KB |
testcase_37 | AC | 2,067 ms
104,016 KB |
testcase_38 | AC | 80 ms
75,932 KB |
ソースコード
#!/usr/bin/env python import sys import math if sys.version_info[0] == 2: range, input = xrange, raw_input class FenwickTree: def __init__(self, a_list): # 0-indexed self.N = len(a_list) self.bit = a_list[:] for _ in range(self.N, 1 << int(math.ceil(math.log(self.N, 2)))): self.bit.append(0) for i in range(self.N-1): self.bit[i | (i+1)] += self.bit[i] def add(self, i, val): while i < self.N: self.bit[i] += val i |= i + 1 def sum(self, n): """[0, n)""" ret = 0 n -= 1 while n >= 0: ret += self.bit[n] n = (n & (n + 1)) - 1 return ret def index(self, k): return self.sum(k + 1) - self.sum(k) def count_index(self, k): left, right = -1, self.N - 1 while left + 1 < right: mid = (left + right) >> 1 if self.sum(mid + 1) >= k: right = mid else: left = mid return right def solve(Q, events): up_events = [0] * (Q + 1) for i, (t, x) in enumerate(events): if t == 3: up_events[i + 1] = x up_events[i + 1] += up_events[i] final_powers = [] for i, (t, x) in enumerate(events): if t == 1: final_power = x + up_events[Q] - up_events[i] final_powers.append((final_power, i)) final_powers.sort() N = len(final_powers) # print(final_powers) idx2fwt = [-1] * Q for i, (_, idx) in enumerate(final_powers): idx2fwt[idx] = i get_into_labo = [] in_labo = FenwickTree([0] * N) answers = [] for i, (t, x) in enumerate(events): if t == 1: # assert(-10 ** 9 <= x <= 10 ** 9) # assert(idx2fwt[i] != -1) # assert(in_labo.index(idx2fwt[i]) == 0) in_labo.add(idx2fwt[i], 1) get_into_labo.append(i) elif t == 2: # assert(1 <= x < i + 1) # assert(in_labo.index(idx2fwt[get_into_labo[x - 1]]) == 1) in_labo.add(idx2fwt[get_into_labo[x - 1]], -1) elif t == 3: # assert(-10 ** 9 <= x <= 10 ** 9) pass else: assert(False) pass # print([in_labo.index(i) for i in range(N)]) num_members = in_labo.sum(N) left, right = 0, num_members + 1 while left + 1 < right: mid = (left + right) >> 1 idx = in_labo.count_index(num_members - mid + 1) orig = final_powers[idx][1] now_power = events[orig][1] + up_events[i + 1] - up_events[orig] # print(left, mid, right, idx) if now_power >= mid: left = mid else: right = mid # print(left) answers.append(left) for x in answers: print(x) if __name__ == '__main__': Q = int(input()) # assert(1 <= Q <= 2 * 10 ** 5) events = [tuple(map(int, input().split())) for _ in range(Q)] solve(Q, events)