結果
| 問題 | No.3469 ジャッジ結果の逆転数 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-03-06 22:40:22 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 557 bytes |
| 記録 | |
| コンパイル時間 | 579 ms |
| コンパイル使用メモリ | 85,764 KB |
| 実行使用メモリ | 148,184 KB |
| 最終ジャッジ日時 | 2026-03-06 22:40:26 |
| 合計ジャッジ時間 | 3,192 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 RE * 12 |
ソースコード
from collections import defaultdict
def inversion(A):
BIT=[0 for _ in range(N+1)]
def BIT_add(x,w):
while x<=N:
BIT[x]+=w
x+=(x&-x)
def BIT_sum(x):
ret=0
while x>0:
ret+=BIT[x]
x-=(x&-x)
return ret
inv=0
for a in reversed(A):
inv+=BIT_sum(a+1)
BIT_add(a+1,1)
return inv
N=int(input())
A=list(map(lambda x:int(x)-1,input().split()))
D=defaultdict(int)
for a in A:
D[a]+=1
ans=inversion(A)
for v in D.values():
ans-=v-1
print(ans)