結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
12,416 KB
testcase_01 AC 28 ms
10,880 KB
testcase_02 AC 32 ms
10,752 KB
testcase_03 AC 389 ms
25,656 KB
testcase_04 AC 461 ms
30,872 KB
testcase_05 AC 405 ms
24,568 KB
testcase_06 AC 368 ms
25,040 KB
testcase_07 AC 450 ms
30,692 KB
testcase_08 AC 46 ms
11,648 KB
testcase_09 AC 235 ms
22,796 KB
testcase_10 AC 414 ms
30,780 KB
testcase_11 AC 28 ms
10,880 KB
testcase_12 AC 473 ms
30,676 KB
testcase_13 AC 471 ms
30,756 KB
testcase_14 AC 469 ms
30,644 KB
testcase_15 AC 29 ms
10,752 KB
testcase_16 AC 29 ms
10,752 KB
testcase_17 AC 28 ms
10,752 KB
testcase_18 AC 28 ms
10,752 KB
testcase_19 AC 28 ms
10,752 KB
testcase_20 AC 28 ms
10,752 KB
testcase_21 AC 28 ms
10,752 KB
testcase_22 AC 28 ms
10,752 KB
testcase_23 AC 58 ms
12,416 KB
testcase_24 AC 178 ms
17,572 KB
testcase_25 AC 358 ms
24,392 KB
testcase_26 AC 94 ms
14,080 KB
testcase_27 AC 202 ms
21,244 KB
testcase_28 AC 276 ms
23,072 KB
testcase_29 AC 357 ms
25,380 KB
testcase_30 AC 439 ms
30,176 KB
testcase_31 AC 120 ms
16,004 KB
testcase_32 AC 84 ms
13,800 KB
testcase_33 AC 360 ms
25,684 KB
testcase_34 AC 28 ms
10,752 KB
testcase_35 AC 29 ms
10,880 KB
testcase_36 AC 29 ms
10,752 KB
testcase_37 AC 28 ms
10,752 KB
testcase_38 AC 29 ms
10,752 KB
testcase_39 AC 27 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BinaryIndexTree:  # 1-indexed
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
btoi = {b: i for i, b in enumerate(B, 1)}

ans = 0
bit = BinaryIndexTree(N + 1)

for i, a in enumerate(A):
    ans += i - bit.sum(btoi[a])
    bit.add(btoi[a], 1)
print(ans)
0