結果

問題 No.1375 Divide and Update
ユーザー 👑 KazunKazun
提出日時 2021-02-05 22:42:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 363 ms / 2,000 ms
コード長 2,020 bytes
コンパイル時間 438 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 188,284 KB
最終ジャッジ日時 2023-09-15 09:22:42
合計ジャッジ時間 6,806 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,364 KB
testcase_01 AC 77 ms
71,352 KB
testcase_02 AC 76 ms
71,400 KB
testcase_03 AC 75 ms
71,520 KB
testcase_04 AC 77 ms
71,476 KB
testcase_05 AC 78 ms
71,372 KB
testcase_06 AC 76 ms
71,368 KB
testcase_07 AC 76 ms
71,600 KB
testcase_08 AC 76 ms
71,440 KB
testcase_09 AC 79 ms
71,424 KB
testcase_10 AC 313 ms
152,604 KB
testcase_11 AC 278 ms
179,972 KB
testcase_12 AC 205 ms
106,748 KB
testcase_13 AC 191 ms
99,532 KB
testcase_14 AC 343 ms
171,068 KB
testcase_15 AC 334 ms
170,816 KB
testcase_16 AC 363 ms
144,996 KB
testcase_17 AC 353 ms
145,720 KB
testcase_18 AC 324 ms
145,160 KB
testcase_19 AC 350 ms
145,304 KB
testcase_20 AC 314 ms
188,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

"""参考元
https://tsubo.hatenablog.jp/entry/2020/06/15/124657
"""

class Heap_Dict:
    def __init__(self,Mode=True):
        """

        Mode:True→最小値,False→最大値
        """
        self.heap=[]
        self.dict={}
        self.Mode=Mode

    def __bool__(self):
        return bool(self.heap)

    def insert(self,x):
        if self.Mode and not self.is_exist(x):
            heapq.heappush(self.heap,x)
        elif not self.Mode and not self.is_exist(x):
            heapq.heappush(self.heap,-x)

        if x in self.dict:
            self.dict[x]+=1
        else:
            self.dict[x]=1

    def erase(self,x):
        assert (x in self.dict) and (self.dict[x])

        self.dict[x]-=1

        while self.heap:
            y=self.heap[0]
            if not self.Mode:y=-y
            if self.dict[y]==0:
                heapq.heappop(self.heap)
            else:
                break

    def is_exist(self,x):
        return (x in self.dict) and (self.dict[x])

    def get_min(self):
        assert self.Mode

        if self.heap:
            return self.heap[0]
        else:
            return float("inf")

    def get_max(self):
        assert not self.Mode

        if self.heap:
            return -self.heap[0]
        else:
            return -float("inf")

    def count(self,x):
        if x not in self.dict:
            return 0
        else:
            return self.dict[x]
#================================================
def gamma(P):
    U=Heap_Dict()
    U.insert(0);U.insert(P[0])
    G=[-inf]*N
    G[0]=P[0]
    alpha=P[0]
    for i in range(1,N):
        alpha+=P[i]
        G[i]=max(G[i-1],alpha-U.get_min())
        U.insert(alpha)
    return G
#================================================
import sys
input=sys.stdin.readline

N,X,Y=map(int,input().split())
A=list(map(int,input().split()))
A_sum=sum(A)
inf=float("inf")

P=gamma([X-a for a in A])
Q=gamma([Y-a for a in A][::-1])[::-1]

for i in range(1,N-1):
    print(A_sum+P[i-1]+Q[i+1])
0