結果

問題 No.703 ゴミ拾い Easy
ユーザー satama6satama6
提出日時 2023-02-12 12:23:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,061 ms / 1,500 ms
コード長 2,677 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 86,912 KB
実行使用メモリ 172,404 KB
最終ジャッジ日時 2023-09-23 04:35:21
合計ジャッジ時間 18,960 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,188 KB
testcase_01 AC 74 ms
70,960 KB
testcase_02 AC 75 ms
71,116 KB
testcase_03 AC 77 ms
71,116 KB
testcase_04 AC 77 ms
71,304 KB
testcase_05 AC 75 ms
71,388 KB
testcase_06 AC 75 ms
71,300 KB
testcase_07 AC 74 ms
71,264 KB
testcase_08 AC 75 ms
71,432 KB
testcase_09 AC 74 ms
71,352 KB
testcase_10 AC 75 ms
71,396 KB
testcase_11 AC 73 ms
71,296 KB
testcase_12 AC 75 ms
71,304 KB
testcase_13 AC 74 ms
71,300 KB
testcase_14 AC 119 ms
77,920 KB
testcase_15 AC 117 ms
78,092 KB
testcase_16 AC 122 ms
77,584 KB
testcase_17 AC 118 ms
78,076 KB
testcase_18 AC 141 ms
78,276 KB
testcase_19 AC 122 ms
77,952 KB
testcase_20 AC 142 ms
79,308 KB
testcase_21 AC 138 ms
78,108 KB
testcase_22 AC 139 ms
78,832 KB
testcase_23 AC 137 ms
78,540 KB
testcase_24 AC 908 ms
169,440 KB
testcase_25 AC 1,001 ms
169,036 KB
testcase_26 AC 1,061 ms
168,740 KB
testcase_27 AC 662 ms
168,544 KB
testcase_28 AC 678 ms
169,668 KB
testcase_29 AC 670 ms
168,488 KB
testcase_30 AC 757 ms
169,036 KB
testcase_31 AC 659 ms
168,464 KB
testcase_32 AC 836 ms
168,828 KB
testcase_33 AC 1,043 ms
168,888 KB
testcase_34 AC 388 ms
171,148 KB
testcase_35 AC 383 ms
171,376 KB
testcase_36 AC 420 ms
171,888 KB
testcase_37 AC 391 ms
171,396 KB
testcase_38 AC 409 ms
171,872 KB
testcase_39 AC 416 ms
171,784 KB
testcase_40 AC 379 ms
171,248 KB
testcase_41 AC 381 ms
171,452 KB
testcase_42 AC 394 ms
170,848 KB
testcase_43 AC 392 ms
171,236 KB
testcase_44 AC 76 ms
71,292 KB
testcase_45 AC 74 ms
71,108 KB
testcase_46 AC 392 ms
171,068 KB
testcase_47 AC 431 ms
172,404 KB
testcase_48 AC 116 ms
78,016 KB
testcase_49 AC 135 ms
77,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class LiChaoTree:
    def __init__(self, M, A) -> None:
        """
        最小値クエリで聞かれる{x1, ..., xn}が既知の時(クエリ先読み)

        """
        self.M = M # クエリ数
        l = 1
        while l < M:
            l <<= 1
        self.length = l
        self.sg = [None] * (2 * l)  # (a, b)直線
        self.X = [1 << 60] * l
        self.update_X(A)
    
    def update_X(self, A):
        self.X = A + [1 << 60] * (self.length - self.M)

    def get_value(self, line, x):
        """座標xにおける直線lineの値
        """
        return line[0] * x + line[1]
    
    def _add_line(self, line, k, l, r):
        """トップダウンに更新
        右、左、真ん中を比較して、lineが必要か不要かを判定
        Parameter
        -----------
        k: 現在処理している区間に対応するセグ木上のインデックス
        l: 現在処理している区間に対応する座標の左端
        r: 現在処理している区間に対応する座標の右端
        """

        if self.sg[k] is None : self.sg[k] = line; return

        m = (l + r) // 2
        lx, mx, rx = self.X[l], self.X[m], self.X[r-1]
        left = self.get_value(line, lx) < self.get_value(self.sg[k], lx)  # 左端
        middle = self.get_value(line, mx) < self.get_value(self.sg[k], mx)  # 真ん中
        right = self.get_value(line, rx) < self.get_value(self.sg[k], rx)  # 右端
        
        # 元々の直線よりもlineの方が値が小さい
        if left and right:self.sg[k] = line; return
        # 元々の直線の方がlineよりも値が小さい
        elif not (left or right) : return
        
        # 元々の直線とlineが交わっている、かつ真ん中でlineの方が小さい
        if middle : self.sg[k], line = line, self.sg[k]

        # 左側をlineに更新しなければならない
        if left != middle : self._add_line(line, 2*k, l, m)
        # 右側をlineに更新しなければならない
        else : self._add_line(line, 2*k+1, m, r)
    
    def add_line(self, line):
        self._add_line(line, 1, 0, self.length)
    
    def gen(self, k, x):
        k += self.length
        while k > 0:
            if self.sg[k] is not None : yield self.get_value(self.sg[k], x)
            k >>= 1

    def query(self, k, x):
        return min(self.gen(k, x))


N = int(input())
A = list(map(int, input().split()))
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
lichao = LiChaoTree(N, A)

v = 0
for i in range(N):
    lichao.add_line((-2*X[i], X[i]**2 + Y[i]**2 + v))
    v = lichao.query(i, A[i]) + A[i]**2

print(v)
0