結果
| 問題 |
No.2404 Vertical Throw Up
|
| コンテスト | |
| ユーザー |
gr1msl3y
|
| 提出日時 | 2023-08-14 11:53:13 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 540 ms / 2,000 ms |
| コード長 | 2,877 bytes |
| コンパイル時間 | 170 ms |
| コンパイル使用メモリ | 81,988 KB |
| 実行使用メモリ | 94,404 KB |
| 最終ジャッジ日時 | 2024-11-22 08:43:08 |
| 合計ジャッジ時間 | 7,139 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
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')
gr1msl3y