結果

問題 No.2404 Vertical Throw Up
ユーザー とりゐとりゐ
提出日時 2023-08-04 22:55:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 267 ms / 2,000 ms
コード長 1,782 bytes
コンパイル時間 568 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 98,292 KB
最終ジャッジ日時 2024-04-22 21:16:41
合計ジャッジ時間 5,094 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,352 KB
testcase_01 AC 38 ms
52,480 KB
testcase_02 AC 38 ms
52,352 KB
testcase_03 AC 218 ms
91,776 KB
testcase_04 AC 192 ms
89,948 KB
testcase_05 AC 244 ms
97,236 KB
testcase_06 AC 42 ms
53,120 KB
testcase_07 AC 267 ms
98,292 KB
testcase_08 AC 212 ms
92,032 KB
testcase_09 AC 199 ms
88,168 KB
testcase_10 AC 128 ms
79,524 KB
testcase_11 AC 126 ms
78,976 KB
testcase_12 AC 112 ms
78,976 KB
testcase_13 AC 49 ms
62,448 KB
testcase_14 AC 57 ms
65,420 KB
testcase_15 AC 54 ms
64,256 KB
testcase_16 AC 49 ms
62,192 KB
testcase_17 AC 61 ms
67,200 KB
testcase_18 AC 60 ms
67,200 KB
testcase_19 AC 49 ms
62,068 KB
testcase_20 AC 50 ms
61,568 KB
testcase_21 AC 60 ms
66,688 KB
testcase_22 AC 49 ms
61,824 KB
testcase_23 AC 47 ms
60,160 KB
testcase_24 AC 60 ms
67,072 KB
testcase_25 AC 45 ms
60,288 KB
testcase_26 AC 56 ms
64,896 KB
testcase_27 AC 59 ms
66,304 KB
testcase_28 AC 45 ms
59,520 KB
testcase_29 AC 41 ms
53,376 KB
testcase_30 AC 40 ms
52,736 KB
testcase_31 AC 48 ms
61,952 KB
testcase_32 AC 41 ms
53,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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())
queries=[]
X=set()
for _ in range(q):
  query=list(map(int,input().split()))
  if query[0]==2:
    X.add(query[1])
  queries.append(query)

LCT=LiChaoTree(X)
flag=False
for query in queries:
  if query[0]==1:
    flag=True
    s,t=query[1:]
    LCT.add_line(-(s+t),s*t)
  else:
    t=query[1]
    ans=0
    if flag:
      ans=max(ans,-LCT.get_min(t)-t*t)
    print(ans*a)
0