結果

問題 No.2089 置換の符号
ユーザー MasKoaTSMasKoaTS
提出日時 2022-09-30 21:47:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 593 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 77,812 KB
最終ジャッジ日時 2023-08-24 15:16:05
合計ジャッジ時間 4,157 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,272 KB
testcase_01 AC 72 ms
71,424 KB
testcase_02 AC 72 ms
71,284 KB
testcase_03 AC 72 ms
71,232 KB
testcase_04 AC 73 ms
71,184 KB
testcase_05 AC 71 ms
71,116 KB
testcase_06 AC 73 ms
71,204 KB
testcase_07 AC 72 ms
71,208 KB
testcase_08 AC 70 ms
71,092 KB
testcase_09 AC 71 ms
71,300 KB
testcase_10 AC 74 ms
71,244 KB
testcase_11 AC 71 ms
71,208 KB
testcase_12 AC 72 ms
71,236 KB
testcase_13 AC 72 ms
71,240 KB
testcase_14 AC 71 ms
71,256 KB
testcase_15 AC 72 ms
71,080 KB
testcase_16 AC 71 ms
71,208 KB
testcase_17 AC 72 ms
71,052 KB
testcase_18 AC 71 ms
71,232 KB
testcase_19 AC 72 ms
71,228 KB
testcase_20 AC 72 ms
71,272 KB
testcase_21 AC 73 ms
71,256 KB
testcase_22 AC 74 ms
71,220 KB
testcase_23 AC 78 ms
75,748 KB
testcase_24 AC 79 ms
75,808 KB
testcase_25 AC 79 ms
75,640 KB
testcase_26 AC 82 ms
75,596 KB
testcase_27 AC 85 ms
76,404 KB
testcase_28 AC 84 ms
76,440 KB
testcase_29 AC 87 ms
77,452 KB
testcase_30 AC 87 ms
77,812 KB
testcase_31 AC 90 ms
77,464 KB
testcase_32 AC 89 ms
77,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

class BIT:
	def __init__(self, N):
		self.N = N
		self.bit = [0] * (N + 1)
		self.b = 1 << N.bit_length() - 1

	def add(self, a, w):
		x = a + 1
		while(x <= self.N):
			self.bit[x] += w
			x += x & -x

	def sum(self, a):
		ret, x = 0, a
		while(x > 0):
			ret += self.bit[x]
			x -= x & -x
		return ret

	def rsum(self, l, r):
		return self.sum(r) - self.sum(l)

"""
Main Code
"""

n = int(input())
a = map(int, input().split())

bt = BIT(n)
rev = 0
for i, k in enumerate(a):
	bt.add(k, 1)
	rev += i - bt.sum(k)

if(rev & 1):
	print(-1)
else:
	print(1)
0