結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー abc abcabc abc
提出日時 2021-05-25 14:27:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 824 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 82,508 KB
実行使用メモリ 110,472 KB
最終ジャッジ日時 2024-04-22 01:46:45
合計ジャッジ時間 4,815 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
76,800 KB
testcase_01 AC 32 ms
52,096 KB
testcase_02 AC 34 ms
52,608 KB
testcase_03 AC 110 ms
109,440 KB
testcase_04 AC 118 ms
103,040 KB
testcase_05 AC 113 ms
110,472 KB
testcase_06 AC 106 ms
109,568 KB
testcase_07 AC 117 ms
103,112 KB
testcase_08 AC 47 ms
72,064 KB
testcase_09 AC 89 ms
101,760 KB
testcase_10 AC 108 ms
103,424 KB
testcase_11 AC 32 ms
52,736 KB
testcase_12 AC 116 ms
103,344 KB
testcase_13 AC 117 ms
103,424 KB
testcase_14 AC 118 ms
103,424 KB
testcase_15 AC 31 ms
52,352 KB
testcase_16 AC 31 ms
52,352 KB
testcase_17 AC 32 ms
52,480 KB
testcase_18 AC 32 ms
52,352 KB
testcase_19 AC 32 ms
52,344 KB
testcase_20 AC 32 ms
52,608 KB
testcase_21 AC 32 ms
52,352 KB
testcase_22 AC 35 ms
52,608 KB
testcase_23 AC 53 ms
76,800 KB
testcase_24 AC 70 ms
87,424 KB
testcase_25 AC 102 ms
110,040 KB
testcase_26 AC 59 ms
79,872 KB
testcase_27 AC 84 ms
92,928 KB
testcase_28 AC 96 ms
101,940 KB
testcase_29 AC 107 ms
109,824 KB
testcase_30 AC 114 ms
103,580 KB
testcase_31 AC 63 ms
82,060 KB
testcase_32 AC 58 ms
78,656 KB
testcase_33 AC 107 ms
109,312 KB
testcase_34 AC 33 ms
51,968 KB
testcase_35 AC 33 ms
52,096 KB
testcase_36 AC 36 ms
52,736 KB
testcase_37 AC 36 ms
52,608 KB
testcase_38 AC 35 ms
52,224 KB
testcase_39 AC 34 ms
52,352 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