結果

問題 No.1435 Mmm......
ユーザー rlangevinrlangevin
提出日時 2023-08-18 12:23:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,334 ms / 2,000 ms
コード長 1,119 bytes
コンパイル時間 590 ms
コンパイル使用メモリ 86,792 KB
実行使用メモリ 112,012 KB
最終ジャッジ日時 2023-08-18 12:24:03
合計ジャッジ時間 19,215 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,556 KB
testcase_01 AC 97 ms
71,544 KB
testcase_02 AC 79 ms
71,580 KB
testcase_03 AC 78 ms
71,224 KB
testcase_04 AC 78 ms
71,452 KB
testcase_05 AC 79 ms
71,424 KB
testcase_06 AC 823 ms
96,952 KB
testcase_07 AC 691 ms
99,808 KB
testcase_08 AC 762 ms
106,124 KB
testcase_09 AC 832 ms
102,844 KB
testcase_10 AC 633 ms
99,648 KB
testcase_11 AC 664 ms
99,672 KB
testcase_12 AC 696 ms
97,276 KB
testcase_13 AC 647 ms
96,848 KB
testcase_14 AC 515 ms
90,728 KB
testcase_15 AC 1,334 ms
106,044 KB
testcase_16 AC 686 ms
99,780 KB
testcase_17 AC 527 ms
92,628 KB
testcase_18 AC 761 ms
106,440 KB
testcase_19 AC 599 ms
97,092 KB
testcase_20 AC 769 ms
103,232 KB
testcase_21 AC 220 ms
107,468 KB
testcase_22 AC 433 ms
112,012 KB
testcase_23 AC 851 ms
107,828 KB
testcase_24 AC 776 ms
107,724 KB
testcase_25 AC 770 ms
108,224 KB
testcase_26 AC 723 ms
108,220 KB
testcase_27 AC 741 ms
108,228 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