結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー brthyyjp
提出日時 2020-07-17 21:38:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 482 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 109,952 KB
最終ジャッジ日時 2024-11-29 22:24:15
合計ジャッジ時間 5,060 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

D = {}
for i, b in enumerate(B):
    D[b] = i
A = [D[a] for a in A]
#print(A)

# 1-indexed
bit = [0]*(n+1)

def bit_query(i):
    res = 0
    while i > 0:
        res += bit[i]
        i -= i & (-i)
    return res

def bit_update(i, x):
    while i <= n:
        bit[i] += x
        i += i & (-i)

ans = 0
for j in range(n):
    ans += j-bit_query(A[j])
    bit_update(A[j]+1, 1)

print(ans)
0