結果
| 問題 |
No.1115 二つの数列 / Two Sequences
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-12-13 22:10:18 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 122 ms / 2,000 ms |
| コード長 | 694 bytes |
| コンパイル時間 | 206 ms |
| コンパイル使用メモリ | 82,252 KB |
| 実行使用メモリ | 105,912 KB |
| 最終ジャッジ日時 | 2024-07-22 21:45:02 |
| 合計ジャッジ時間 | 5,752 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 35 |
ソースコード
n = int(input())
a = list(map(int, input().split()))
B = list(map(int, input().split()))
#簡単のため、aを1, 2, 3,4, …だとして考えるための操作
tmp = [0]*(n+1)
for i in range(n):
tmp[a[i]] = i+1
b = [0]*n
for i in range(n):
b[i] = tmp[B[i]]
# i<j かつ b[i]>b[j]となる組の個数が求めるもの(∵操作によって左の数が1減るから)
# 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(b[j])
bit_update(b[j], 1)
print(ans)