結果
| 問題 |
No.2089 置換の符号
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-09-30 21:30:21 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 74 ms / 2,000 ms |
| コード長 | 618 bytes |
| コンパイル時間 | 166 ms |
| コンパイル使用メモリ | 82,400 KB |
| 実行使用メモリ | 76,784 KB |
| 最終ジャッジ日時 | 2024-12-22 22:26:20 |
| 合計ジャッジ時間 | 3,209 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
import sys
input = sys.stdin.readline
from collections import *
class BIT:
def __init__(self, n):
self.n = n
self.bit = [0]*(n+1)
def add(self, i, x):
i += 1
while i<=self.n:
self.bit[i] += x
i += i&(-i)
def acc(self, i):
s = 0
while i>0:
s += self.bit[i]
i -= i&(-i)
return s
N = int(input())
S = list(map(int, input().split()))
bit = BIT(N)
inv = 0
for i in range(N):
inv += i-bit.acc(S[i])
bit.add(S[i]-1, 1)
if inv%2==0:
print(1)
else:
print(-1)