結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー mkawa2mkawa2
提出日時 2021-03-12 22:56:58
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 3,660 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 170,276 KB
最終ジャッジ日時 2024-04-22 14:24:36
合計ジャッジ時間 16,799 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
54,784 KB
testcase_01 AC 48 ms
54,528 KB
testcase_02 AC 48 ms
54,784 KB
testcase_03 AC 47 ms
54,784 KB
testcase_04 AC 48 ms
54,912 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 47 ms
54,400 KB
testcase_08 WA -
testcase_09 AC 48 ms
54,656 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 48 ms
54,912 KB
testcase_13 AC 48 ms
54,656 KB
testcase_14 AC 48 ms
54,784 KB
testcase_15 WA -
testcase_16 AC 48 ms
54,528 KB
testcase_17 AC 48 ms
54,656 KB
testcase_18 WA -
testcase_19 AC 49 ms
54,912 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 345 ms
146,180 KB
testcase_23 AC 148 ms
95,616 KB
testcase_24 AC 134 ms
92,800 KB
testcase_25 AC 354 ms
152,828 KB
testcase_26 AC 401 ms
167,408 KB
testcase_27 AC 370 ms
153,976 KB
testcase_28 AC 421 ms
168,164 KB
testcase_29 AC 202 ms
100,096 KB
testcase_30 AC 169 ms
97,792 KB
testcase_31 AC 428 ms
167,904 KB
testcase_32 AC 188 ms
98,048 KB
testcase_33 AC 112 ms
78,592 KB
testcase_34 AC 199 ms
101,760 KB
testcase_35 AC 412 ms
160,204 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 48 ms
54,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
# md = 998244353
md = 10**9+7

from collections import defaultdict
from bisect import bisect

class SegtreeMin():
    def __init__(self, n):
        self.inf = 10**16
        aa = []
        if not isinstance(n, int):
            aa = n
            n = len(aa)
        self.tree_width = tw = 1 << (n-1).bit_length()
        self.tree = [self.inf]*(tw*2-1)
        if aa:
            self.tree[tw-1:tw-1+len(aa)] = aa
            for i in range(tw-2, -1, -1):
                self.tree[i] = min(self.tree[i*2+1], self.tree[i*2+2])

    def update(self, i, a):
        seg_i = self.tree_width-1+i
        self.tree[seg_i] = a
        while seg_i != 0:
            seg_i = (seg_i-1)//2
            self.tree[seg_i] = min(self.tree[seg_i*2+1], self.tree[seg_i*2+2])

    def element(self, i):
        return self.tree[self.tree_width-1+i]

    # [l,r)の最小値
    def min(self, l, r):
        if l==r:return self.inf
        res = self.inf
        stack = [(0, 0, self.tree_width)]
        while stack:
            seg_i, segL, segR = stack.pop()
            if l <= segL and segR <= r:
                if self.tree[seg_i] < res: res = self.tree[seg_i]
            else:
                segM = (segL+segR)//2
                if r > segL and segM > l:
                    stack.append((seg_i*2+1, segL, segM))
                if r > segM and segR > l:
                    stack.append((seg_i*2+2, segM, segR))
        return res

    # [l,r)でaより小さい要素のうち最右のインデックス
    def LessR(self, l, r, a):
        stack = [(0, 0, self.tree_width)]
        while stack:
            u, ul, ur = stack.pop()
            if ur-ul == 1: return u-self.tree_width+1
            um = (ul+ur)//2
            if self.tree[u*2+1] < a and ul < r and l < um:
                stack.append((u*2+1, ul, um))
            if self.tree[u*2+2] < a and um < r and l < ur:
                stack.append((u*2+2, um, ur))
        return -1

    # [l,r)でaより小さい要素のうち最左のインデックス
    def LessL(self, l, r, a):
        stack = [(0, 0, self.tree_width)]
        while stack:
            u, ul, ur = stack.pop()
            if ur-ul == 1: return u-self.tree_width+1
            um = (ul+ur)//2
            if self.tree[u*2+2] < a and um < r and l < ur:
                stack.append((u*2+2, um, ur))
            if self.tree[u*2+1] < a and ul < r and l < um:
                stack.append((u*2+1, ul, um))
        return -1

n=II()
aa=LI()
st=SegtreeMin(aa)
atoi=defaultdict(list)
for i,a in enumerate(aa):
    atoi[a].append(i)

ans=0
now=n-1
for a in sorted(set(aa),reverse=True):
    ii=atoi[a]
    j=bisect(ii,now)-1
    if j==-1:j=len(ii)-1
    if ii[j]<=now:
        if st.min(ii[j],now)<a:ans+=1
    else:
        if min(st.min(0,now),st.min(ii[j],n))<a:ans+=1
    for _ in range(len(ii)-1):
        if j and ii[j]-ii[j-1]>1 :ans+=1
        if j==0 and ii[j]-ii[j-1]!=-n+1 :ans+=1
        j=(j-1)%len(ii)
    now=ii[j]
    # print(a,ans)

print(ans)
0