結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー rlangevinrlangevin
提出日時 2023-10-04 12:52:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,167 bytes
コンパイル時間 764 ms
コンパイル使用メモリ 87,248 KB
実行使用メモリ 161,684 KB
最終ジャッジ日時 2023-10-04 12:53:03
合計ジャッジ時間 19,220 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
71,976 KB
testcase_01 AC 97 ms
71,764 KB
testcase_02 AC 96 ms
71,924 KB
testcase_03 AC 96 ms
71,980 KB
testcase_04 AC 98 ms
71,564 KB
testcase_05 AC 95 ms
71,688 KB
testcase_06 WA -
testcase_07 AC 99 ms
71,732 KB
testcase_08 AC 96 ms
71,628 KB
testcase_09 AC 98 ms
71,724 KB
testcase_10 AC 101 ms
71,532 KB
testcase_11 WA -
testcase_12 AC 96 ms
71,440 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 97 ms
71,908 KB
testcase_16 AC 97 ms
71,536 KB
testcase_17 AC 98 ms
71,724 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 373 ms
146,056 KB
testcase_23 AC 206 ms
96,236 KB
testcase_24 AC 199 ms
93,588 KB
testcase_25 AC 396 ms
151,456 KB
testcase_26 AC 419 ms
145,220 KB
testcase_27 AC 583 ms
156,660 KB
testcase_28 AC 486 ms
146,632 KB
testcase_29 AC 331 ms
105,320 KB
testcase_30 AC 293 ms
98,988 KB
testcase_31 AC 471 ms
144,760 KB
testcase_32 AC 313 ms
102,580 KB
testcase_33 AC 220 ms
81,764 KB
testcase_34 AC 356 ms
108,724 KB
testcase_35 AC 480 ms
161,684 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 96 ms
71,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from heapq import *

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()))
A.reverse()
D = defaultdict(list)
for i in range(N):
    D[A[i]].append(i)

for k, v in D.items():
    D[k].reverse()

L = []
A.sort()
for i in range(N - 1, -1, -1):
    L.append(D[A[i]].pop())

H = QuasiBinaryTree("min")
H2 = QuasiBinaryTree("min")
for i in range(N):
    H.insert(i)
    H2.insert(i)

ans = 0
pre = -1
flag = 0
for i in range(N):
    if L[i] != pre + 1 and (L[i] != H.top() or flag):
        ans += 1
    pre = L[i]
    if pre == H2.top():
        flag = 1
    else:
        flag = 0
    H.erase(L[i])
    H2.erase(L[i])

print(ans)
0