結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー takakintakakin
提出日時 2020-07-17 21:30:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 668 ms / 2,000 ms
コード長 532 bytes
コンパイル時間 551 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 33,164 KB
最終ジャッジ日時 2024-05-07 07:02:44
合計ジャッジ時間 12,918 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
14,208 KB
testcase_01 AC 32 ms
12,672 KB
testcase_02 AC 31 ms
12,800 KB
testcase_03 AC 577 ms
28,716 KB
testcase_04 AC 654 ms
33,164 KB
testcase_05 AC 573 ms
29,164 KB
testcase_06 AC 516 ms
27,732 KB
testcase_07 AC 644 ms
32,988 KB
testcase_08 AC 65 ms
13,696 KB
testcase_09 AC 375 ms
24,240 KB
testcase_10 AC 622 ms
32,840 KB
testcase_11 AC 32 ms
12,672 KB
testcase_12 AC 667 ms
32,712 KB
testcase_13 AC 668 ms
32,664 KB
testcase_14 AC 666 ms
32,836 KB
testcase_15 AC 33 ms
12,800 KB
testcase_16 AC 31 ms
12,672 KB
testcase_17 AC 32 ms
12,672 KB
testcase_18 AC 32 ms
12,672 KB
testcase_19 AC 31 ms
12,672 KB
testcase_20 AC 32 ms
12,672 KB
testcase_21 AC 32 ms
12,672 KB
testcase_22 AC 32 ms
12,672 KB
testcase_23 AC 84 ms
14,208 KB
testcase_24 AC 248 ms
19,456 KB
testcase_25 AC 504 ms
27,176 KB
testcase_26 AC 143 ms
16,080 KB
testcase_27 AC 306 ms
22,120 KB
testcase_28 AC 405 ms
24,496 KB
testcase_29 AC 520 ms
27,700 KB
testcase_30 AC 626 ms
32,112 KB
testcase_31 AC 181 ms
17,692 KB
testcase_32 AC 131 ms
15,792 KB
testcase_33 AC 555 ms
28,880 KB
testcase_34 AC 33 ms
12,800 KB
testcase_35 AC 32 ms
12,800 KB
testcase_36 AC 32 ms
12,672 KB
testcase_37 AC 32 ms
12,800 KB
testcase_38 AC 32 ms
12,800 KB
testcase_39 AC 32 ms
12,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
D=dict()
for i,a in enumerate(A):
  D[a]=i
C=[]
for b in B:
  C.append(D[b]+1)

n_max=10**5
nn=n_max.bit_length()+1
BIT=[0]*(2**nn)
BIT.insert(0,0)

def bitsum(BIT,i):
  s=0
  while i>0:
    s+=BIT[i]
    i-=i&(-i)
  return s

def bitadd(BIT,i,x):
  while i<=2**nn:
    BIT[i]+=x
    i+=i&(-i)
  return BIT

ans=0
for i in range(n):
  ans+=i-bitsum(BIT,C[i])
  bitadd(BIT,C[i],1)
print(ans)
0