結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー ああいい
提出日時 2022-02-23 13:56:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 161 ms / 2,000 ms
コード長 399 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 82,492 KB
実行使用メモリ 111,652 KB
最終ジャッジ日時 2024-07-01 13:41:12
合計ジャッジ時間 5,759 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
D = {v:i for i,v in enumerate(b)}
bit = [0] * (n+1)
def update(i,x):
    while i <= n:
        bit[i] += x
        i += i & -i
def fold(i):
    ans = 0
    while i > 0:
        ans += bit[i]
        i -= i & -i
    return ans
ans = 0
for x in reversed(a):
    ans += fold(D[x]+1)
    update(D[x]+1,1)
print(ans)
0