結果

問題 No.2089 置換の符号
ユーザー H3PO4H3PO4
提出日時 2022-09-30 21:30:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 535 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 10,876 KB
実行使用メモリ 9,332 KB
最終ジャッジ日時 2023-08-24 14:47:40
合計ジャッジ時間 2,168 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,804 KB
testcase_01 AC 16 ms
7,836 KB
testcase_02 AC 16 ms
7,844 KB
testcase_03 AC 15 ms
7,800 KB
testcase_04 AC 15 ms
7,824 KB
testcase_05 AC 15 ms
7,764 KB
testcase_06 AC 15 ms
7,984 KB
testcase_07 AC 15 ms
7,900 KB
testcase_08 AC 15 ms
7,960 KB
testcase_09 AC 15 ms
7,916 KB
testcase_10 AC 15 ms
7,760 KB
testcase_11 AC 15 ms
7,880 KB
testcase_12 AC 16 ms
7,828 KB
testcase_13 AC 15 ms
7,992 KB
testcase_14 AC 15 ms
7,824 KB
testcase_15 AC 15 ms
7,884 KB
testcase_16 AC 15 ms
7,824 KB
testcase_17 AC 15 ms
7,840 KB
testcase_18 AC 15 ms
7,912 KB
testcase_19 AC 16 ms
7,992 KB
testcase_20 AC 15 ms
7,840 KB
testcase_21 AC 16 ms
7,812 KB
testcase_22 AC 16 ms
7,884 KB
testcase_23 AC 16 ms
7,808 KB
testcase_24 AC 17 ms
7,764 KB
testcase_25 AC 16 ms
7,764 KB
testcase_26 AC 17 ms
8,364 KB
testcase_27 AC 21 ms
8,240 KB
testcase_28 AC 33 ms
9,192 KB
testcase_29 AC 40 ms
9,296 KB
testcase_30 AC 41 ms
9,332 KB
testcase_31 AC 41 ms
9,288 KB
testcase_32 AC 40 ms
9,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Bit:
    """1-indexed"""

    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


N = int(input())
M = tuple(map(int, input().split()))
bit = Bit(N)
ans = 0

for i, m in enumerate(M):
    bit.add(m, 1)
    ans += i + 1 - bit.sum(m)

print(-1 if ans % 2 else 1)
0