結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー tyawanmusityawanmusi
提出日時 2020-02-04 17:39:52
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 613 ms / 2,000 ms
コード長 695 bytes
コンパイル時間 109 ms
コンパイル使用メモリ 10,872 KB
実行使用メモリ 25,932 KB
最終ジャッジ日時 2023-07-28 19:48:12
合計ジャッジ時間 12,687 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
9,580 KB
testcase_01 AC 16 ms
7,768 KB
testcase_02 AC 16 ms
7,768 KB
testcase_03 AC 522 ms
23,304 KB
testcase_04 AC 548 ms
25,484 KB
testcase_05 AC 488 ms
23,224 KB
testcase_06 AC 430 ms
21,952 KB
testcase_07 AC 613 ms
25,556 KB
testcase_08 AC 39 ms
9,160 KB
testcase_09 AC 326 ms
18,604 KB
testcase_10 AC 515 ms
25,804 KB
testcase_11 AC 16 ms
7,800 KB
testcase_12 AC 544 ms
25,932 KB
testcase_13 AC 543 ms
25,812 KB
testcase_14 AC 545 ms
25,888 KB
testcase_15 AC 16 ms
7,812 KB
testcase_16 AC 16 ms
7,812 KB
testcase_17 AC 16 ms
7,828 KB
testcase_18 AC 16 ms
7,740 KB
testcase_19 AC 17 ms
7,812 KB
testcase_20 AC 15 ms
7,824 KB
testcase_21 AC 16 ms
7,768 KB
testcase_22 AC 16 ms
7,912 KB
testcase_23 AC 51 ms
9,700 KB
testcase_24 AC 191 ms
14,876 KB
testcase_25 AC 433 ms
21,384 KB
testcase_26 AC 95 ms
11,204 KB
testcase_27 AC 248 ms
16,368 KB
testcase_28 AC 360 ms
18,784 KB
testcase_29 AC 453 ms
22,008 KB
testcase_30 AC 540 ms
24,976 KB
testcase_31 AC 135 ms
12,352 KB
testcase_32 AC 96 ms
10,940 KB
testcase_33 AC 466 ms
23,516 KB
testcase_34 AC 16 ms
7,768 KB
testcase_35 AC 17 ms
7,792 KB
testcase_36 AC 16 ms
7,764 KB
testcase_37 AC 16 ms
7,756 KB
testcase_38 AC 17 ms
7,876 KB
testcase_39 AC 16 ms
7,876 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