結果
| 問題 | No.1115 二つの数列 / Two Sequences |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-24 22:17:25 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 167 ms / 2,000 ms |
| コード長 | 693 bytes |
| コンパイル時間 | 158 ms |
| コンパイル使用メモリ | 82,260 KB |
| 実行使用メモリ | 104,412 KB |
| 最終ジャッジ日時 | 2024-06-25 21:46:06 |
| 合計ジャッジ時間 | 5,589 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 35 |
ソースコード
import sys
input = sys.stdin.readline
from collections import *
class BIT:
def __init__(self, n):
self.n = n
self.bit = [0]*(n+1)
def add(self, i, x):
i += 1
while i<=self.n:
self.bit[i] += x
i += i&(-i)
def acc(self, i):
s = 0
while i>0:
s += self.bit[i]
i -= i&(-i)
return s
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = defaultdict(int)
for i in range(n):
d[b[i]] = i
bit = BIT(n)
ans = 0
for i in range(n):
ans += i-bit.acc(d[a[i]])
bit.add(d[a[i]], 1)
print(ans)