結果
| 問題 |
No.2404 Vertical Throw Up
|
| コンテスト | |
| ユーザー |
timi
|
| 提出日時 | 2024-02-28 13:49:35 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 263 ms / 2,000 ms |
| コード長 | 1,703 bytes |
| コンパイル時間 | 192 ms |
| コンパイル使用メモリ | 82,584 KB |
| 実行使用メモリ | 101,016 KB |
| 最終ジャッジ日時 | 2024-09-29 12:19:58 |
| 合計ジャッジ時間 | 4,859 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
INF = 1 << 60
class LiChaoTree(object):
def __init__(self, X):
X = sorted(set(X))
N = 1 << (len(X) - 1).bit_length()
self._tree = [None] * (N << 1)
self._N, self._X = N, X + [INF] * (N - len(X))
self._X_inv = {x : i for i, x in enumerate(X)}
def add_line(self, a, b):
tree, X = self._tree, self._X
i, l, r = 1, 0, self._N
while r - l:
if tree[i] is None:
tree[i] = (a, b)
return
m = (l + r) >> 1
xl, xm, xr = X[l], X[m], X[r-1]
ai, bi = tree[i]
left = a * xl + b < ai * xl + bi
mid = a * xm + b < ai * xm + bi
right = a * xr + b < ai * xr + bi
if left is right:
if left:
tree[i] = (a, b)
return
if mid:
tree[i], a, b = (a, b), ai, bi
if left is not mid:
i, r = i << 1, m
else:
i, l = i << 1 | 1, m
def get_min(self, x):
i = self._X_inv[x]
i += self._N
res = INF
tree = self._tree
while i:
if tree[i] is not None:
a, b = tree[i]
res = min(res, a * x + b)
i >>= 1
return res
from sys import stdin
input=lambda :stdin.readline()[:-1]
a=int(input())
Q=int(input())
S=[]
X=set()
for _ in range(Q):
t,*A=list(map(int, input().split()))
if t==2:
X.add(A[0])
S.append((t,*A))
LCT=LiChaoTree(X)
for query in S:
if query[0]==1:
s,t=query[1:]
LCT.add_line(-(s+t),s*t)
else:
t=query[1]
ans=max(0,-LCT.get_min(t)-t*t)
print(ans*a)
timi