結果
| 問題 | No.3469 ジャッジ結果の逆転数 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-03-06 22:40:22 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 557 bytes |
| 記録 | |
| コンパイル時間 | 242 ms |
| コンパイル使用メモリ | 95,720 KB |
| 実行使用メモリ | 156,152 KB |
| 最終ジャッジ日時 | 2026-07-27 07:08:49 |
| 合計ジャッジ時間 | 5,114 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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)