結果

問題 No.2404 Vertical Throw Up
ユーザー とりゐとりゐ
提出日時 2023-08-04 22:55:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 249 ms / 2,000 ms
コード長 1,722 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 82,168 KB
実行使用メモリ 98,900 KB
最終ジャッジ日時 2024-04-22 21:15:42
合計ジャッジ時間 4,302 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
52,884 KB
testcase_01 AC 33 ms
52,872 KB
testcase_02 AC 31 ms
52,512 KB
testcase_03 AC 212 ms
93,072 KB
testcase_04 AC 190 ms
90,008 KB
testcase_05 AC 249 ms
98,900 KB
testcase_06 AC 37 ms
54,244 KB
testcase_07 AC 248 ms
98,884 KB
testcase_08 AC 205 ms
92,868 KB
testcase_09 AC 193 ms
89,408 KB
testcase_10 AC 125 ms
79,992 KB
testcase_11 AC 128 ms
79,944 KB
testcase_12 AC 109 ms
78,908 KB
testcase_13 AC 46 ms
63,596 KB
testcase_14 AC 52 ms
67,304 KB
testcase_15 AC 65 ms
66,396 KB
testcase_16 AC 46 ms
63,580 KB
testcase_17 AC 70 ms
69,984 KB
testcase_18 AC 79 ms
70,796 KB
testcase_19 AC 65 ms
63,756 KB
testcase_20 AC 63 ms
63,192 KB
testcase_21 AC 61 ms
69,940 KB
testcase_22 AC 48 ms
63,292 KB
testcase_23 AC 43 ms
61,748 KB
testcase_24 AC 68 ms
69,584 KB
testcase_25 AC 44 ms
61,248 KB
testcase_26 AC 51 ms
66,776 KB
testcase_27 AC 53 ms
67,032 KB
testcase_28 AC 40 ms
60,840 KB
testcase_29 AC 35 ms
55,676 KB
testcase_30 AC 34 ms
54,804 KB
testcase_31 AC 57 ms
63,056 KB
testcase_32 AC 36 ms
55,120 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

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