結果

問題 No.1435 Mmm......
ユーザー rlangevinrlangevin
提出日時 2023-08-18 12:23:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,299 ms / 2,000 ms
コード長 1,119 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 113,060 KB
最終ジャッジ日時 2024-05-05 17:44:42
合計ジャッジ時間 17,764 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
54,400 KB
testcase_01 AC 45 ms
54,400 KB
testcase_02 AC 44 ms
54,272 KB
testcase_03 AC 44 ms
54,656 KB
testcase_04 AC 46 ms
53,888 KB
testcase_05 AC 43 ms
54,656 KB
testcase_06 AC 719 ms
95,232 KB
testcase_07 AC 695 ms
98,032 KB
testcase_08 AC 732 ms
104,012 KB
testcase_09 AC 822 ms
100,608 KB
testcase_10 AC 632 ms
97,744 KB
testcase_11 AC 641 ms
97,680 KB
testcase_12 AC 699 ms
94,720 KB
testcase_13 AC 589 ms
95,104 KB
testcase_14 AC 466 ms
88,576 KB
testcase_15 AC 1,299 ms
103,936 KB
testcase_16 AC 633 ms
97,900 KB
testcase_17 AC 503 ms
90,240 KB
testcase_18 AC 725 ms
104,172 KB
testcase_19 AC 582 ms
95,608 KB
testcase_20 AC 734 ms
100,840 KB
testcase_21 AC 207 ms
113,060 KB
testcase_22 AC 394 ms
111,760 KB
testcase_23 AC 861 ms
101,340 KB
testcase_24 AC 776 ms
101,048 KB
testcase_25 AC 807 ms
101,016 KB
testcase_26 AC 696 ms
100,664 KB
testcase_27 AC 701 ms
100,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
from collections import *
import sys
input = sys.stdin.readline
 
class QuasiBinaryTree:
    def __init__(self, rule="min"):
        if rule == "max":
            self.pm = -1
        else:
            self.pm = 1
 
        self.inf = 10**18
        self.P = [self.inf]
        self.Q = []
 
    def insert(self, x):
        heappush(self.P, x * self.pm)
 
    def erase(self, x):
        heappush(self.Q, x * self.pm)
 
    def top(self):
        while self.Q and (self.P[0] == self.Q[0]):
            heappop(self.P)
            heappop(self.Q)
        return self.P[0] * self.pm
    



N = int(input())
A = list(map(int, input().split()))

T1, T2 = QuasiBinaryTree("min"), QuasiBinaryTree("max")
Q = deque()
ans = 0
for i in range(N):
    T1.insert(A[i])
    T2.insert(A[i])
    Q.append(A[i])
    while len(Q) >= 2:
        ma = T2.top()
        mi = T1.top()
        T1.erase(mi)
        mi2 = T1.top()
        T1.insert(mi)
        if mi + mi2 >= ma:
            break
        else:
            q = Q.popleft()
            T1.erase(q)
            T2.erase(q)
    ans += len(Q) - 1

print(ans)
0