結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー tyawanmusityawanmusi
提出日時 2020-02-04 18:00:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 834 ms / 2,000 ms
コード長 696 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 28,600 KB
最終ジャッジ日時 2024-04-16 03:43:17
合計ジャッジ時間 13,907 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
12,160 KB
testcase_01 AC 32 ms
10,752 KB
testcase_02 AC 32 ms
10,752 KB
testcase_03 AC 732 ms
26,080 KB
testcase_04 AC 757 ms
28,308 KB
testcase_05 AC 683 ms
25,524 KB
testcase_06 AC 588 ms
24,680 KB
testcase_07 AC 834 ms
28,200 KB
testcase_08 AC 61 ms
11,904 KB
testcase_09 AC 454 ms
20,864 KB
testcase_10 AC 686 ms
28,596 KB
testcase_11 AC 32 ms
10,752 KB
testcase_12 AC 763 ms
28,584 KB
testcase_13 AC 758 ms
28,596 KB
testcase_14 AC 769 ms
28,600 KB
testcase_15 AC 32 ms
10,752 KB
testcase_16 AC 32 ms
10,752 KB
testcase_17 AC 32 ms
10,752 KB
testcase_18 AC 32 ms
10,752 KB
testcase_19 AC 32 ms
10,752 KB
testcase_20 AC 32 ms
10,752 KB
testcase_21 AC 32 ms
10,752 KB
testcase_22 AC 32 ms
10,752 KB
testcase_23 AC 76 ms
12,288 KB
testcase_24 AC 272 ms
17,080 KB
testcase_25 AC 582 ms
24,056 KB
testcase_26 AC 140 ms
14,080 KB
testcase_27 AC 339 ms
18,616 KB
testcase_28 AC 510 ms
21,140 KB
testcase_29 AC 634 ms
24,756 KB
testcase_30 AC 758 ms
27,196 KB
testcase_31 AC 196 ms
15,104 KB
testcase_32 AC 138 ms
13,824 KB
testcase_33 AC 632 ms
25,748 KB
testcase_34 AC 31 ms
10,752 KB
testcase_35 AC 31 ms
10,752 KB
testcase_36 AC 32 ms
10,752 KB
testcase_37 AC 32 ms
10,752 KB
testcase_38 AC 32 ms
10,880 KB
testcase_39 AC 31 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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[a[i]]=i
print(tentousu([c[i]for i in b]))
0