結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー kojihashimoto-kobekojihashimoto-kobe
提出日時 2021-12-13 22:10:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 694 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 104,236 KB
最終ジャッジ日時 2023-09-30 03:45:54
合計ジャッジ時間 6,583 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
77,480 KB
testcase_01 AC 75 ms
71,140 KB
testcase_02 AC 71 ms
71,448 KB
testcase_03 AC 137 ms
101,720 KB
testcase_04 AC 146 ms
100,516 KB
testcase_05 AC 136 ms
102,356 KB
testcase_06 AC 131 ms
99,552 KB
testcase_07 AC 144 ms
100,532 KB
testcase_08 AC 84 ms
76,672 KB
testcase_09 AC 117 ms
93,264 KB
testcase_10 AC 142 ms
100,884 KB
testcase_11 AC 74 ms
71,148 KB
testcase_12 AC 146 ms
100,636 KB
testcase_13 AC 143 ms
101,000 KB
testcase_14 AC 141 ms
100,924 KB
testcase_15 AC 70 ms
71,596 KB
testcase_16 AC 70 ms
71,240 KB
testcase_17 AC 71 ms
71,332 KB
testcase_18 AC 70 ms
71,288 KB
testcase_19 AC 74 ms
71,492 KB
testcase_20 AC 73 ms
71,120 KB
testcase_21 AC 70 ms
71,544 KB
testcase_22 AC 70 ms
71,648 KB
testcase_23 AC 87 ms
77,396 KB
testcase_24 AC 105 ms
84,680 KB
testcase_25 AC 129 ms
99,060 KB
testcase_26 AC 91 ms
78,580 KB
testcase_27 AC 107 ms
87,376 KB
testcase_28 AC 120 ms
93,384 KB
testcase_29 AC 134 ms
99,436 KB
testcase_30 AC 143 ms
104,236 KB
testcase_31 AC 97 ms
80,380 KB
testcase_32 AC 91 ms
78,280 KB
testcase_33 AC 135 ms
102,092 KB
testcase_34 AC 72 ms
71,240 KB
testcase_35 AC 71 ms
71,376 KB
testcase_36 AC 70 ms
71,372 KB
testcase_37 AC 71 ms
71,368 KB
testcase_38 AC 69 ms
71,412 KB
testcase_39 AC 70 ms
71,120 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)

print(ans)
0