結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー tyawanmusityawanmusi
提出日時 2020-02-04 17:39:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 831 ms / 2,000 ms
コード長 695 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 28,188 KB
最終ジャッジ日時 2024-04-16 03:43:02
合計ジャッジ時間 14,442 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
12,160 KB
testcase_01 AC 32 ms
10,752 KB
testcase_02 AC 32 ms
10,752 KB
testcase_03 AC 737 ms
25,460 KB
testcase_04 AC 763 ms
28,188 KB
testcase_05 AC 690 ms
25,412 KB
testcase_06 AC 589 ms
24,328 KB
testcase_07 AC 831 ms
28,080 KB
testcase_08 AC 61 ms
11,776 KB
testcase_09 AC 456 ms
20,608 KB
testcase_10 AC 677 ms
27,924 KB
testcase_11 AC 31 ms
10,752 KB
testcase_12 AC 764 ms
28,064 KB
testcase_13 AC 767 ms
28,064 KB
testcase_14 AC 763 ms
28,068 KB
testcase_15 AC 32 ms
10,752 KB
testcase_16 AC 31 ms
10,752 KB
testcase_17 AC 31 ms
10,752 KB
testcase_18 AC 31 ms
10,624 KB
testcase_19 AC 32 ms
10,752 KB
testcase_20 AC 31 ms
10,624 KB
testcase_21 AC 32 ms
10,752 KB
testcase_22 AC 32 ms
10,624 KB
testcase_23 AC 77 ms
12,160 KB
testcase_24 AC 275 ms
17,084 KB
testcase_25 AC 590 ms
23,808 KB
testcase_26 AC 140 ms
13,824 KB
testcase_27 AC 342 ms
18,488 KB
testcase_28 AC 501 ms
21,144 KB
testcase_29 AC 653 ms
24,628 KB
testcase_30 AC 776 ms
27,236 KB
testcase_31 AC 194 ms
14,972 KB
testcase_32 AC 138 ms
13,440 KB
testcase_33 AC 633 ms
25,756 KB
testcase_34 AC 32 ms
10,624 KB
testcase_35 AC 32 ms
10,752 KB
testcase_36 AC 32 ms
10,752 KB
testcase_37 AC 31 ms
10,752 KB
testcase_38 AC 32 ms
10,752 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[b[i]]=i
print(tentousu([c[i]for i in a]))
0