結果
| 問題 | No.1115 二つの数列 / Two Sequences |
| コンテスト | |
| ユーザー |
tyawanmusi
|
| 提出日時 | 2020-02-04 17:39:52 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 734 ms / 2,000 ms |
| コード長 | 695 bytes |
| コンパイル時間 | 152 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 28,304 KB |
| 最終ジャッジ日時 | 2024-10-06 14:46:36 |
| 合計ジャッジ時間 | 13,100 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 35 |
ソースコード
class BinaryIndexedTree():
def __init__(self,n):self.bit=[0]*n
def add(self,i,x):
i+=1
while i<=len(self.bit):
self.bit[i-1]+=x
i+=i&-i
def sum_1(self,i):
a=0
i+=1
while i:
a+=self.bit[i-1]
i-=i&-i
return a
def sum(self,i,j):
a=self.sum_1(j-1)
if i!=0:a-=self.sum_1(i-1)
return a
def tentousu(a):
bit=BinaryIndexedTree(n)
b=[0]*n
for i in range(n):
b[a[i]]=i
ans=0
for i in range(n):
j=b[i]+bit.sum(b[i]+1,n)
ans+=j-i
bit.add(b[i],1)
return ans
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[0]*(n+1)
for i in range(n):c[b[i]]=i
print(tentousu([c[i]for i in a]))
tyawanmusi