結果
| 問題 |
No.2404 Vertical Throw Up
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-08-05 17:49:07 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 294 ms / 2,000 ms |
| コード長 | 1,930 bytes |
| コンパイル時間 | 233 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 112,640 KB |
| 最終ジャッジ日時 | 2024-10-15 14:51:33 |
| 合計ジャッジ時間 | 6,191 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')
from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
# sys.setrecursionlimit(10**6)
input = sys.stdin.readline
a = int(input())
Q = int(input())
query = [tuple(map(int,input().split())) for _ in range(Q)]
class CHT:
def __init__(self, X: list) -> None:
X = sorted([*set(X)])
self.inf = 10 ** 18
self.n = 1 << (len(X) - 1).bit_length()
self.X =X + [self.inf] * (self.n - len(X))
self.D = {a: i for i, a in enumerate(X)}
self.lmr = [(0, 0, 0)] * self.n + [(x, x, x) for x in self.X]
for i in range(1, self.n)[::-1]:
self.lmr[i] = (self.lmr[i * 2][0], self.lmr[i * 2][2], self.lmr[i * 2 ^ 1][2])
self.F = [None] * (self.n * 2)
def calc(self, f: tuple, x: int) -> int:
a, b = f
return a * x + b
def _update(self, i, f):
while True:
l, m, r = self.lmr[i]
fi = self.F[i]
if fi is None:
self.F[i] = f
return
cl = self.calc(fi, l) > self.calc(f, l)
cr = self.calc(fi, r) > self.calc(f, r)
cm = self.calc(fi, m) > self.calc(f, m)
if cl and cr:
self.F[i] = f
return
if not cl and not cr:
return
if cm:
self.F[i], f = f, fi
cl = not cl
if cl:
i *= 2
else:
i = i * 2 + 1
def query(self, x):
i = self.D[x] + self.n
mi = self.inf
while i > 0:
if self.F[i]:
mi = min(mi, self.calc(self.F[i], x))
i >>= 1
return mi
def add_line(self, a, b):
f = (a, b)
self._update(1, f)
X = []
for q in query:
if q[0]==2:
t = q[1]
X.append(t)
cht = CHT(X)
for q in query:
if q[0]==1:
s,t = q[1:]
A = -a*(s+t)
B = a*s*t
cht.add_line(A,B)
else:
t = q[1]
print(max(-a*t**2 - cht.query(t),0))