結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー abc abcabc abc
提出日時 2021-05-25 14:27:46
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 824 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 105,796 KB
最終ジャッジ日時 2023-08-04 03:18:39
合計ジャッジ時間 8,291 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
77,744 KB
testcase_01 AC 69 ms
71,380 KB
testcase_02 AC 69 ms
71,376 KB
testcase_03 AC 148 ms
100,028 KB
testcase_04 AC 169 ms
105,424 KB
testcase_05 AC 153 ms
100,252 KB
testcase_06 AC 145 ms
97,792 KB
testcase_07 AC 168 ms
105,296 KB
testcase_08 AC 89 ms
76,908 KB
testcase_09 AC 132 ms
102,672 KB
testcase_10 AC 162 ms
105,644 KB
testcase_11 AC 73 ms
71,316 KB
testcase_12 AC 174 ms
105,752 KB
testcase_13 AC 168 ms
105,740 KB
testcase_14 AC 165 ms
105,796 KB
testcase_15 AC 71 ms
71,016 KB
testcase_16 AC 71 ms
71,264 KB
testcase_17 AC 71 ms
70,888 KB
testcase_18 AC 70 ms
71,376 KB
testcase_19 AC 72 ms
71,216 KB
testcase_20 AC 72 ms
71,356 KB
testcase_21 AC 74 ms
71,304 KB
testcase_22 AC 74 ms
71,356 KB
testcase_23 AC 92 ms
77,784 KB
testcase_24 AC 113 ms
89,008 KB
testcase_25 AC 143 ms
99,728 KB
testcase_26 AC 96 ms
80,924 KB
testcase_27 AC 118 ms
93,692 KB
testcase_28 AC 134 ms
102,936 KB
testcase_29 AC 145 ms
98,004 KB
testcase_30 AC 161 ms
103,332 KB
testcase_31 AC 107 ms
83,416 KB
testcase_32 AC 94 ms
79,784 KB
testcase_33 AC 146 ms
100,452 KB
testcase_34 AC 71 ms
71,212 KB
testcase_35 AC 69 ms
71,104 KB
testcase_36 AC 70 ms
71,344 KB
testcase_37 AC 68 ms
71,228 KB
testcase_38 AC 70 ms
71,016 KB
testcase_39 AC 70 ms
71,312 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_number(li):
    #para li:list
    #list内部の要素は正であることが必要らしい
    #return : 転倒数
    bit = Bit(max(li))
    res = 0
    for i, l in enumerate(li):
        bit.add(l, 1)
        res += i + 1 - bit.sum(l)
    return res


n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

bi = dict()
for i in range(n):
    bi[b[i]]=i
c = [bi[a[i]]+1 for i in range(n)]

print(inversion_number(c))
0