結果
| 問題 | No.1115 二つの数列 / Two Sequences |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-06-15 09:23:36 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 200 ms / 2,000 ms |
| コード長 | 782 bytes |
| コンパイル時間 | 245 ms |
| コンパイル使用メモリ | 81,920 KB |
| 実行使用メモリ | 108,928 KB |
| 最終ジャッジ日時 | 2024-12-26 03:24:25 |
| 合計ジャッジ時間 | 7,184 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 35 |
ソースコード
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
d={}
for i,x in enumerate(b):
d[x]=i+1
ary=[]
for x in a:
ary.append(d[x])
# Binary Indexed Tree (Fenwick Tree)
# 1-indexed
class BIT:
def __init__(self, n):
self.n = n
self.data = [0]*(n+1)
self.el = [0]*(n+1)
# sum(ary[:i])
def sum(self, i):
s = 0
while i > 0:
s += self.data[i]
i -= i & -i
return s
# ary[i]+=x
def add(self, i, x):
# assert i > 0
self.el[i] += x
while i <= self.n:
self.data[i] += x
i += i & -i
# sum(ary[i:j])
def get(self, i, j=None):
if j is None:
return self.el[i]
return self.sum(j) - self.sum(i)
bit=BIT(n)
ans=0
for i,x in enumerate(ary):
ans+=i-bit.sum(x)
bit.add(x,1)
print(ans)