結果

問題 No.2089 置換の符号
ユーザー とりゐとりゐ
提出日時 2022-09-30 22:29:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 612 bytes
コンパイル時間 1,282 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 78,012 KB
最終ジャッジ日時 2023-08-24 16:04:49
合計ジャッジ時間 4,712 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,300 KB
testcase_01 AC 72 ms
71,276 KB
testcase_02 AC 72 ms
71,308 KB
testcase_03 AC 71 ms
71,400 KB
testcase_04 AC 71 ms
71,292 KB
testcase_05 AC 71 ms
71,208 KB
testcase_06 AC 72 ms
71,088 KB
testcase_07 AC 72 ms
71,392 KB
testcase_08 AC 71 ms
71,336 KB
testcase_09 AC 71 ms
71,212 KB
testcase_10 AC 72 ms
71,284 KB
testcase_11 AC 72 ms
71,304 KB
testcase_12 AC 71 ms
71,308 KB
testcase_13 AC 72 ms
71,288 KB
testcase_14 AC 72 ms
71,300 KB
testcase_15 AC 72 ms
71,284 KB
testcase_16 AC 73 ms
71,388 KB
testcase_17 AC 71 ms
71,284 KB
testcase_18 AC 76 ms
71,216 KB
testcase_19 AC 72 ms
71,436 KB
testcase_20 AC 72 ms
71,320 KB
testcase_21 AC 72 ms
71,372 KB
testcase_22 AC 73 ms
71,368 KB
testcase_23 AC 77 ms
75,792 KB
testcase_24 AC 79 ms
75,640 KB
testcase_25 AC 77 ms
75,548 KB
testcase_26 AC 78 ms
75,744 KB
testcase_27 AC 86 ms
76,584 KB
testcase_28 AC 94 ms
77,392 KB
testcase_29 AC 96 ms
77,528 KB
testcase_30 AC 95 ms
78,012 KB
testcase_31 AC 94 ms
77,884 KB
testcase_32 AC 95 ms
77,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Bit:
  def __init__(self,n):
    self.size=n
    self.tree=[0]*(n+1)
  
  def sum(self, i):
    s=0
    while i>0:
      s+=self.tree[i]
      i-=i&-i
    return s
  
  def add(self,i,x):
    while i<=self.size:
      self.tree[i]+=x
      i+=i&-i

def inversion(a,flag=True):
  n=len(a)
  if flag:
    b=[(a[i],i+1) for i in range(n)]
    b.sort(key=lambda x:x[0])
    a=[i[1] for i in b]

  bit=Bit(n)
  cnt=0
  for i in range(n):
    bit.add(a[i],1)
    cnt+=i+1-bit.sum(a[i])
  return cnt

n=int(input())
a=list(map(lambda x:int(x)-1,input().split()))
if inversion(a)%2==0:
  print(1)
else:
  print(-1)
0