結果

問題 No.1604 Swap Sort:ONE
ユーザー DrDrpilot
提出日時 2022-03-05 18:41:01
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 675 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-07-20 00:48:12
合計ジャッジ時間 2,603 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

class Bit:
    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
def inversion(L):
    #座圧パート
    N=len(L)
    s=sorted(list(set(L)))
    M=len(s)
    d={ }
    for i,x in enumerate(s):
        d[x]=i+1
    #BITパート
    cnt=0
    bit=Bit(M)
    for i in range(N):
        bit.add(d[L[i]],1)
        cnt+=bit.sum(M)-bit.sum(d[L[i]])
    return cnt
n=int(input())
a=list(map(int,input().split()))
print(inversion(a))
0