結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー takakintakakin
提出日時 2020-07-17 21:30:00
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 548 ms / 2,000 ms
コード長 532 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 10,764 KB
実行使用メモリ 30,492 KB
最終ジャッジ日時 2023-08-19 23:47:57
合計ジャッジ時間 10,568 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
11,916 KB
testcase_01 AC 20 ms
10,292 KB
testcase_02 AC 23 ms
10,292 KB
testcase_03 AC 460 ms
26,160 KB
testcase_04 AC 532 ms
30,360 KB
testcase_05 AC 463 ms
26,724 KB
testcase_06 AC 424 ms
25,056 KB
testcase_07 AC 523 ms
30,492 KB
testcase_08 AC 48 ms
11,372 KB
testcase_09 AC 304 ms
22,496 KB
testcase_10 AC 499 ms
30,172 KB
testcase_11 AC 21 ms
10,276 KB
testcase_12 AC 541 ms
30,232 KB
testcase_13 AC 548 ms
30,176 KB
testcase_14 AC 541 ms
30,100 KB
testcase_15 AC 21 ms
10,348 KB
testcase_16 AC 21 ms
10,232 KB
testcase_17 AC 20 ms
10,192 KB
testcase_18 AC 21 ms
10,220 KB
testcase_19 AC 21 ms
10,360 KB
testcase_20 AC 20 ms
10,344 KB
testcase_21 AC 20 ms
10,192 KB
testcase_22 AC 21 ms
10,392 KB
testcase_23 AC 63 ms
12,008 KB
testcase_24 AC 200 ms
17,676 KB
testcase_25 AC 397 ms
24,044 KB
testcase_26 AC 110 ms
13,664 KB
testcase_27 AC 249 ms
19,684 KB
testcase_28 AC 326 ms
22,460 KB
testcase_29 AC 425 ms
24,628 KB
testcase_30 AC 516 ms
29,836 KB
testcase_31 AC 143 ms
15,392 KB
testcase_32 AC 101 ms
13,364 KB
testcase_33 AC 446 ms
26,776 KB
testcase_34 AC 21 ms
10,216 KB
testcase_35 AC 20 ms
10,360 KB
testcase_36 AC 21 ms
10,196 KB
testcase_37 AC 21 ms
10,216 KB
testcase_38 AC 20 ms
10,296 KB
testcase_39 AC 21 ms
10,192 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