結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-03-15 11:41:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,277 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 82,768 KB
実行使用メモリ 229,020 KB
最終ジャッジ日時 2024-04-24 15:45:57
合計ジャッジ時間 15,114 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,016 KB
testcase_01 AC 43 ms
54,144 KB
testcase_02 AC 40 ms
54,016 KB
testcase_03 WA -
testcase_04 AC 42 ms
54,144 KB
testcase_05 AC 42 ms
54,144 KB
testcase_06 WA -
testcase_07 AC 41 ms
54,016 KB
testcase_08 WA -
testcase_09 AC 41 ms
54,400 KB
testcase_10 AC 40 ms
54,144 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 41 ms
54,400 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 39 ms
54,272 KB
testcase_18 AC 41 ms
54,144 KB
testcase_19 WA -
testcase_20 AC 41 ms
54,400 KB
testcase_21 AC 42 ms
54,144 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 144 ms
97,792 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 111 ms
79,104 KB
testcase_34 WA -
testcase_35 WA -
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 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
a=list(map(int,input().split()))
la=list(set(a))
la.sort()
pa={x:i for i,x in enumerate(la)}
a=[pa[x] for x in a]
from collections import Counter
from bisect import bisect_left as bl,bisect_right as br
a.append(len(la))
ca=dict(Counter(a))
aa=a+a
ary=[[] for _ in range(len(ca))]
for i,x in enumerate(aa):
  ary[x].append(i)

# 0-indexed binary indexed tree
class BIT:
  def __init__(self, n):
    self.n = n
    self.data = [0]*(n+1)
    self.el = [0]*(n+1)
  # sum of [0,i) sum(a[:i])
  def sum(self, i):
    if i==0:return 0
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self, i, x):
    i+=1
    self.el[i] += x
    while i <= self.n:
      self.data[i] += x
      i += i & -i
  # sum of [l,r)   sum(a[l:r])
  def sumlr(self, i, j):
    return self.sum(j) - self.sum(i)
  # a[i]
  def get(self,i):
    i+=1
    return self.el[i]

bit=BIT(2*n*2)
for i in range(2*n+2):bit.add(i,1)
now=2*n+1
v=len(la)
ans=0
bit.add(now,-1)
bit.add(now-n-1,-1)
for _ in range(n):
  ca[v]-=1
  if ca[v]==0:
    v-=1
  # nowより左のidxの中で最も右のvを探す
  idx=br(ary[v],now)-1
  if bit.sumlr(ary[v][idx]+1,now):
    ans+=1
  now=ary[v][idx]
  if now<n+1:now+=n+1
  bit.add(now,-1)
  bit.add(now-n-1,-1)

print(ans)

0