結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-03-15 12:03:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,512 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 228,796 KB
最終ジャッジ日時 2024-04-24 16:00:59
合計ジャッジ時間 13,007 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,528 KB
testcase_01 AC 44 ms
54,016 KB
testcase_02 AC 46 ms
54,272 KB
testcase_03 AC 43 ms
54,272 KB
testcase_04 AC 43 ms
54,016 KB
testcase_05 AC 45 ms
54,144 KB
testcase_06 WA -
testcase_07 AC 44 ms
54,144 KB
testcase_08 WA -
testcase_09 AC 43 ms
54,400 KB
testcase_10 AC 43 ms
54,272 KB
testcase_11 WA -
testcase_12 AC 43 ms
54,272 KB
testcase_13 AC 45 ms
54,272 KB
testcase_14 AC 44 ms
53,888 KB
testcase_15 WA -
testcase_16 AC 43 ms
54,400 KB
testcase_17 AC 42 ms
54,144 KB
testcase_18 AC 44 ms
53,888 KB
testcase_19 AC 44 ms
53,888 KB
testcase_20 AC 45 ms
54,400 KB
testcase_21 AC 43 ms
54,400 KB
testcase_22 AC 361 ms
178,952 KB
testcase_23 AC 149 ms
100,608 KB
testcase_24 AC 135 ms
97,920 KB
testcase_25 AC 379 ms
206,548 KB
testcase_26 AC 527 ms
227,068 KB
testcase_27 AC 383 ms
206,980 KB
testcase_28 AC 435 ms
227,228 KB
testcase_29 AC 180 ms
119,168 KB
testcase_30 AC 164 ms
103,296 KB
testcase_31 AC 429 ms
227,464 KB
testcase_32 AC 173 ms
115,200 KB
testcase_33 AC 95 ms
78,720 KB
testcase_34 AC 192 ms
118,656 KB
testcase_35 AC 428 ms
215,520 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 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 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]

from collections import Counter
from bisect import bisect_left as bl,bisect_right as br
def main1(n,a):
  la=list(set(a))
  la.sort()
  pa={x:i for i,x in enumerate(la)}
  a=[pa[x] for x in a]
  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)

  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)-1
    #print('idx,now',ary[v][idx],now)
    if bit.sumlr(ary[v][idx]+1,now):
      ans+=1
      #print(f'ans add, v={v}',ca,bit.el)
    now=ary[v][idx]
    if now<n+1:now+=n+1
    bit.add(now,-1)
    bit.add(now-n-1,-1)
  #print(bit.el)
  return ans
if __name__=='__main__':
  n=int(input())
  a=list(map(int,input().split()))
  ret1=main1(n,a)
  print(ret1)
0