結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー kojihashimoto-kobekojihashimoto-kobe
提出日時 2021-08-18 12:15:04
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 696 bytes
コンパイル時間 582 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 104,052 KB
最終ジャッジ日時 2023-08-01 21:29:40
合計ジャッジ時間 6,315 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
77,144 KB
testcase_01 AC 72 ms
71,372 KB
testcase_02 AC 69 ms
71,284 KB
testcase_03 AC 139 ms
101,860 KB
testcase_04 AC 149 ms
100,396 KB
testcase_05 AC 137 ms
101,936 KB
testcase_06 AC 138 ms
99,188 KB
testcase_07 AC 149 ms
100,412 KB
testcase_08 AC 86 ms
76,540 KB
testcase_09 AC 115 ms
93,024 KB
testcase_10 AC 143 ms
100,700 KB
testcase_11 AC 71 ms
71,404 KB
testcase_12 AC 142 ms
100,832 KB
testcase_13 AC 130 ms
100,696 KB
testcase_14 AC 138 ms
100,616 KB
testcase_15 AC 67 ms
71,300 KB
testcase_16 AC 66 ms
71,224 KB
testcase_17 AC 65 ms
71,120 KB
testcase_18 AC 68 ms
71,128 KB
testcase_19 AC 66 ms
71,284 KB
testcase_20 AC 67 ms
71,352 KB
testcase_21 AC 67 ms
71,232 KB
testcase_22 AC 65 ms
71,072 KB
testcase_23 AC 83 ms
77,284 KB
testcase_24 AC 102 ms
84,252 KB
testcase_25 AC 122 ms
98,636 KB
testcase_26 AC 88 ms
78,936 KB
testcase_27 AC 101 ms
87,388 KB
testcase_28 AC 113 ms
93,524 KB
testcase_29 AC 125 ms
99,312 KB
testcase_30 AC 133 ms
104,052 KB
testcase_31 AC 90 ms
80,348 KB
testcase_32 AC 87 ms
77,828 KB
testcase_33 AC 129 ms
101,688 KB
testcase_34 AC 68 ms
71,360 KB
testcase_35 AC 68 ms
71,128 KB
testcase_36 AC 68 ms
71,232 KB
testcase_37 AC 69 ms
71,396 KB
testcase_38 AC 67 ms
71,284 KB
testcase_39 AC 68 ms
70,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int, input().split()))
B = list(map(int, input().split()))

#簡単のため、aを1, 2, 3,4, …だとして考えるための操作
tmp = [0]*(n+1)
for i in range(n):
  tmp[a[i]] = i+1

b = [0]*n
for i in range(n):
  b[i] = tmp[B[i]]

# i<j かつ b[i]>b[j]となる組の個数が求めるもの(∵操作によって左の数が1減るから)

# 1-indexed
bit = [0]*(n+1)

def bit_query(i):
    res = 0
    while i > 0:
        res += bit[i]
        i -= i & (-i)
    return res

def bit_update(i, x):
    while i <= n:
        bit[i] += x
        i += i & (-i)

ans = 0
for j in range(n):
    ans += j-bit_query(b[j])
    bit_update(b[j]+1, 1)

print(ans)
0