結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー tktk_snsntktk_snsn
提出日時 2020-07-17 21:33:37
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 408 ms / 2,000 ms
コード長 623 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 28,640 KB
最終ジャッジ日時 2023-08-19 23:57:18
合計ジャッジ時間 8,338 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
9,856 KB
testcase_01 AC 16 ms
7,768 KB
testcase_02 AC 16 ms
7,788 KB
testcase_03 AC 340 ms
22,944 KB
testcase_04 AC 383 ms
28,496 KB
testcase_05 AC 332 ms
23,136 KB
testcase_06 AC 300 ms
22,724 KB
testcase_07 AC 388 ms
28,640 KB
testcase_08 AC 30 ms
9,236 KB
testcase_09 AC 192 ms
20,632 KB
testcase_10 AC 344 ms
28,632 KB
testcase_11 AC 16 ms
7,848 KB
testcase_12 AC 408 ms
28,564 KB
testcase_13 AC 401 ms
28,628 KB
testcase_14 AC 407 ms
28,504 KB
testcase_15 AC 16 ms
7,836 KB
testcase_16 AC 15 ms
7,852 KB
testcase_17 AC 16 ms
7,796 KB
testcase_18 AC 16 ms
7,928 KB
testcase_19 AC 16 ms
7,872 KB
testcase_20 AC 15 ms
7,712 KB
testcase_21 AC 16 ms
7,780 KB
testcase_22 AC 15 ms
7,828 KB
testcase_23 AC 40 ms
9,988 KB
testcase_24 AC 137 ms
15,260 KB
testcase_25 AC 292 ms
23,268 KB
testcase_26 AC 73 ms
11,600 KB
testcase_27 AC 164 ms
19,260 KB
testcase_28 AC 234 ms
21,416 KB
testcase_29 AC 309 ms
22,304 KB
testcase_30 AC 384 ms
27,512 KB
testcase_31 AC 95 ms
13,572 KB
testcase_32 AC 65 ms
11,440 KB
testcase_33 AC 306 ms
24,144 KB
testcase_34 AC 16 ms
7,848 KB
testcase_35 AC 16 ms
7,856 KB
testcase_36 AC 15 ms
7,764 KB
testcase_37 AC 16 ms
7,776 KB
testcase_38 AC 16 ms
7,780 KB
testcase_39 AC 16 ms
7,780 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