結果
問題 | No.2404 Vertical Throw Up |
ユーザー | gr1msl3y |
提出日時 | 2023-08-14 11:53:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 568 ms / 2,000 ms |
コード長 | 2,877 bytes |
コンパイル時間 | 371 ms |
コンパイル使用メモリ | 82,152 KB |
実行使用メモリ | 94,536 KB |
最終ジャッジ日時 | 2024-05-02 00:10:04 |
合計ジャッジ時間 | 7,496 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
53,164 KB |
testcase_01 | AC | 42 ms
53,444 KB |
testcase_02 | AC | 46 ms
53,640 KB |
testcase_03 | AC | 479 ms
90,604 KB |
testcase_04 | AC | 407 ms
87,908 KB |
testcase_05 | AC | 568 ms
94,084 KB |
testcase_06 | AC | 54 ms
62,224 KB |
testcase_07 | AC | 567 ms
94,536 KB |
testcase_08 | AC | 495 ms
90,876 KB |
testcase_09 | AC | 413 ms
87,292 KB |
testcase_10 | AC | 211 ms
79,952 KB |
testcase_11 | AC | 211 ms
79,432 KB |
testcase_12 | AC | 190 ms
78,856 KB |
testcase_13 | AC | 65 ms
67,436 KB |
testcase_14 | AC | 79 ms
72,652 KB |
testcase_15 | AC | 73 ms
70,016 KB |
testcase_16 | AC | 68 ms
67,360 KB |
testcase_17 | AC | 81 ms
73,144 KB |
testcase_18 | AC | 83 ms
74,412 KB |
testcase_19 | AC | 65 ms
67,480 KB |
testcase_20 | AC | 66 ms
67,716 KB |
testcase_21 | AC | 80 ms
73,452 KB |
testcase_22 | AC | 66 ms
67,024 KB |
testcase_23 | AC | 66 ms
65,096 KB |
testcase_24 | AC | 76 ms
72,760 KB |
testcase_25 | AC | 58 ms
63,532 KB |
testcase_26 | AC | 74 ms
70,512 KB |
testcase_27 | AC | 75 ms
71,428 KB |
testcase_28 | AC | 59 ms
63,820 KB |
testcase_29 | AC | 54 ms
62,232 KB |
testcase_30 | AC | 51 ms
60,660 KB |
testcase_31 | AC | 65 ms
67,152 KB |
testcase_32 | AC | 54 ms
61,912 KB |
ソースコード
from bisect import bisect_left class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): i += 1 s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def sumrange(self, i, j): si = self.sum(i - 1) sj = self.sum(j) return sj - si def add(self, i, x): i += 1 while i <= self.size: self.tree[i] += x i += i & -i def lower_bound(self, w): if w <= 0: return 0 x = 0 r = 1 << (self.size).bit_length() while r > 0: if x+r < self.size and self.tree[x+r] < w: w -= self.tree[x+r] x += r r = r >> 1 return x Ga = int(input()) Q = int(input()) query = [list(map(int, input().split())) for _ in range(Q)] lines = [[-1, -10**9]] for q in query: if len(q) == 3: s, t = q[1:] lines.append([s+t, -s*t]) lines.sort() def isneed(ismax, f1, f2, f3): va = (f3[1]-f2[1])*(f2[0]-f1[0]) vb = (f2[1]-f1[1])*(f3[0]-f2[0]) if ismax: return va < vb else: return va > vb def f(ind, t): b, c = lines[ind] return t*b+c state = Bit(Q+2) state.add(0, 1) ans = [] ct = 1 for q in query: if q[0] == 1: s, t = q[1:] b, c = s+t, -s*t ind = bisect_left(lines, [b, c]) w = state.sum(ind-1) if 0 < w < ct: indl = state.lower_bound(w) indr = state.lower_bound(w+1) if not isneed(1, lines[indl], lines[ind], lines[indr]): continue state.add(ind, 1) ct += 1 while w+2 < ct: indr0 = state.lower_bound(w+2) indr1 = state.lower_bound(w+3) if not isneed(1, lines[ind], lines[indr0], lines[indr1]): state.add(indr0, -1) ct -= 1 else: break while 1 < w: indl0 = state.lower_bound(w-1) indl1 = state.lower_bound(w) if not isneed(1, lines[indl0], lines[indl1], lines[ind]): state.add(indl1, -1) ct -= 1 w -= 1 else: break else: t = q[1] res = 0 if ct == 1: ind = state.lower_bound(1) res = f(ind, t) else: ind0 = state.lower_bound(1) res = f(ind0, t) while ct > 1: ind1 = state.lower_bound(2) res1 = f(ind1, t) if res < res1: state.add(ind0, -1) ind0 = ind1 res = res1 ct -= 1 else: break ans.append(max(0, (-t**2+res)*Ga)) print(*ans, sep='\n')