結果
問題 | No.618 labo-index |
ユーザー | mkawa2 |
提出日時 | 2021-12-05 10:27:44 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 859 ms / 6,000 ms |
コード長 | 2,470 bytes |
コンパイル時間 | 1,688 ms |
コンパイル使用メモリ | 87,024 KB |
実行使用メモリ | 122,464 KB |
最終ジャッジ日時 | 2023-09-21 13:21:57 |
合計ジャッジ時間 | 16,995 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 74 ms
71,068 KB |
testcase_01 | AC | 74 ms
71,336 KB |
testcase_02 | AC | 75 ms
71,128 KB |
testcase_03 | AC | 74 ms
71,116 KB |
testcase_04 | AC | 147 ms
77,464 KB |
testcase_05 | AC | 132 ms
78,328 KB |
testcase_06 | AC | 77 ms
75,692 KB |
testcase_07 | AC | 86 ms
75,740 KB |
testcase_08 | AC | 90 ms
76,404 KB |
testcase_09 | AC | 99 ms
76,756 KB |
testcase_10 | AC | 119 ms
77,688 KB |
testcase_11 | AC | 100 ms
76,592 KB |
testcase_12 | AC | 99 ms
76,604 KB |
testcase_13 | AC | 113 ms
77,660 KB |
testcase_14 | AC | 98 ms
76,420 KB |
testcase_15 | AC | 108 ms
77,532 KB |
testcase_16 | AC | 132 ms
78,128 KB |
testcase_17 | AC | 104 ms
76,464 KB |
testcase_18 | AC | 146 ms
79,272 KB |
testcase_19 | AC | 546 ms
99,076 KB |
testcase_20 | AC | 612 ms
100,524 KB |
testcase_21 | AC | 570 ms
99,548 KB |
testcase_22 | AC | 575 ms
99,208 KB |
testcase_23 | AC | 574 ms
99,244 KB |
testcase_24 | AC | 549 ms
99,628 KB |
testcase_25 | AC | 553 ms
100,608 KB |
testcase_26 | AC | 592 ms
99,840 KB |
testcase_27 | AC | 533 ms
99,624 KB |
testcase_28 | AC | 531 ms
99,004 KB |
testcase_29 | AC | 545 ms
100,032 KB |
testcase_30 | AC | 528 ms
98,956 KB |
testcase_31 | AC | 541 ms
100,736 KB |
testcase_32 | AC | 550 ms
99,324 KB |
testcase_33 | AC | 543 ms
99,364 KB |
testcase_34 | AC | 859 ms
122,464 KB |
testcase_35 | AC | 842 ms
122,192 KB |
testcase_36 | AC | 436 ms
96,748 KB |
testcase_37 | AC | 768 ms
105,768 KB |
testcase_38 | AC | 74 ms
71,168 KB |
ソースコード
import sys sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = 18446744073709551615 inf = 4294967295 md = 10**9+7 # md = 998244353 class BitSum: def __init__(self, n): self.n = n+1 self.table = [0]*self.n def add(self, i, x): i += 1 while i < self.n: self.table[i] += x i += i & -i # [0,i]の和 def sum(self, i): i += 1 res = 0 while i > 0: res += self.table[i] i -= i & -i return res # [l,r)の和 def sumlr(self, l, r): if l >= r: return 0 if l == 0: return self.sum(r-1) return self.sum(r-1)-self.sum(l-1) # 数列を度数分布とみたときに、x番目がどのインデックスにあるかを返す # xが大きすぎるときは配列の長さnを返す def rank(self, x): idx = 0 for lv in range((self.n-1).bit_length()-1, -1, -1): mid = idx+(1 << lv) if mid >= self.n: continue if self.table[mid] < x: x -= self.table[mid] idx += 1 << lv return idx q = II() tx = LLI(q) base = 0 xx = set() for t, x in tx: if t == 1: xx.add(x-base) if t == 3: base += x dec = sorted(xx, reverse=True) enc = {a: i for i, a in enumerate(dec)} def binary_search(l, r, ok, minimize): if minimize: l -= 1 else: r += 1 while l+1 < r: m = (l+r)//2 if ok(m) ^ minimize: l = m else: r = m if minimize: return r return l def ok(m): i = bit.rank(m) x = dec[i]+base return x >= m base = 0 bit = BitSum(len(enc)+5) ii = [] n = 0 for t, x in tx: if t == 1: x -= base i = enc[x] bit.add(i, 1) n += 1 ii.append(i) if t == 2: i = ii[x-1] bit.add(i, -1) n -= 1 if t == 3: base += x ans = binary_search(0, n, ok, False) print(ans)