結果

問題 No.2089 置換の符号
ユーザー AkariAkari
提出日時 2022-09-30 22:05:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 589 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 29,940 KB
最終ジャッジ日時 2023-08-24 15:37:38
合計ジャッジ時間 6,968 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
29,684 KB
testcase_01 AC 126 ms
29,612 KB
testcase_02 AC 127 ms
29,624 KB
testcase_03 AC 127 ms
29,600 KB
testcase_04 AC 126 ms
29,664 KB
testcase_05 AC 127 ms
29,660 KB
testcase_06 AC 128 ms
29,564 KB
testcase_07 AC 127 ms
29,616 KB
testcase_08 AC 128 ms
29,668 KB
testcase_09 AC 127 ms
29,736 KB
testcase_10 AC 126 ms
29,704 KB
testcase_11 AC 127 ms
29,616 KB
testcase_12 AC 127 ms
29,664 KB
testcase_13 AC 128 ms
29,736 KB
testcase_14 AC 127 ms
29,680 KB
testcase_15 AC 128 ms
29,484 KB
testcase_16 AC 130 ms
29,588 KB
testcase_17 AC 128 ms
29,628 KB
testcase_18 AC 128 ms
29,608 KB
testcase_19 AC 127 ms
29,552 KB
testcase_20 AC 128 ms
29,592 KB
testcase_21 AC 128 ms
29,588 KB
testcase_22 AC 129 ms
29,620 KB
testcase_23 AC 130 ms
29,620 KB
testcase_24 AC 132 ms
29,736 KB
testcase_25 AC 134 ms
29,752 KB
testcase_26 AC 134 ms
29,640 KB
testcase_27 AC 148 ms
29,772 KB
testcase_28 AC 202 ms
29,848 KB
testcase_29 AC 214 ms
29,864 KB
testcase_30 AC 210 ms
29,824 KB
testcase_31 AC 212 ms
29,872 KB
testcase_32 AC 209 ms
29,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import numpy as np

def fwadd(data, p, x):
    n = data.shape[0]
    p += 1
    while p <= n:
        data[p-1] += x
        p += p & -p

def fwsum(data, l, r):
    s = 0
    while r > 0:
        s += data[r-1]
        r -= r & -r
    while l > 0:
        s -= data[l-1]
        l -= l & -l
    return s



def main():
    n = int(input())
    S = np.fromstring(input(), np.int64, sep=' ') - 1
    fw = np.zeros(n, np.int64)
    a = 0
    for s in S:
        a += fwsum(fw, s, n)
        fwadd(fw, s, 1)
    print(-1 if a & 1 else 1)







if __name__ == '__main__':
    main()
0