結果
| 問題 | 
                            No.1115 二つの数列 / Two Sequences
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-05-25 14:27:46 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 147 ms / 2,000 ms | 
| コード長 | 824 bytes | 
| コンパイル時間 | 182 ms | 
| コンパイル使用メモリ | 82,048 KB | 
| 実行使用メモリ | 110,244 KB | 
| 最終ジャッジ日時 | 2024-10-14 00:24:11 | 
| 合計ジャッジ時間 | 6,147 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 35 | 
ソースコード
#【転倒数】
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))