結果

問題 No.1604 Swap Sort:ONE
ユーザー DrDrpilotDrDrpilot
提出日時 2022-03-05 18:41:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 675 bytes
コンパイル時間 949 ms
コンパイル使用メモリ 10,884 KB
実行使用メモリ 8,912 KB
最終ジャッジ日時 2023-09-27 06:36:07
合計ジャッジ時間 3,582 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
7,760 KB
testcase_01 AC 14 ms
7,844 KB
testcase_02 AC 14 ms
7,836 KB
testcase_03 AC 15 ms
7,876 KB
testcase_04 AC 15 ms
7,972 KB
testcase_05 AC 22 ms
8,868 KB
testcase_06 AC 23 ms
8,832 KB
testcase_07 AC 23 ms
8,788 KB
testcase_08 AC 23 ms
8,788 KB
testcase_09 AC 23 ms
8,912 KB
testcase_10 AC 24 ms
8,832 KB
testcase_11 AC 23 ms
8,856 KB
testcase_12 AC 23 ms
8,840 KB
testcase_13 AC 23 ms
8,792 KB
testcase_14 AC 24 ms
8,792 KB
testcase_15 AC 24 ms
8,896 KB
testcase_16 AC 24 ms
8,836 KB
testcase_17 AC 21 ms
8,540 KB
testcase_18 AC 19 ms
8,564 KB
testcase_19 AC 23 ms
8,844 KB
testcase_20 AC 20 ms
8,652 KB
testcase_21 AC 22 ms
8,840 KB
testcase_22 AC 20 ms
8,616 KB
testcase_23 AC 16 ms
8,400 KB
testcase_24 AC 15 ms
8,336 KB
testcase_25 AC 22 ms
8,896 KB
testcase_26 AC 18 ms
8,544 KB
権限があれば一括ダウンロードができます

ソースコード

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