結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー H3PO4H3PO4
提出日時 2020-07-17 21:35:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 388 ms / 2,000 ms
コード長 606 bytes
コンパイル時間 371 ms
コンパイル使用メモリ 10,860 KB
実行使用メモリ 28,700 KB
最終ジャッジ日時 2023-08-20 00:02:25
合計ジャッジ時間 7,857 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
10,044 KB
testcase_01 AC 15 ms
7,896 KB
testcase_02 AC 15 ms
7,836 KB
testcase_03 AC 323 ms
22,780 KB
testcase_04 AC 383 ms
28,648 KB
testcase_05 AC 325 ms
23,192 KB
testcase_06 AC 295 ms
21,160 KB
testcase_07 AC 379 ms
28,700 KB
testcase_08 AC 29 ms
9,156 KB
testcase_09 AC 189 ms
20,812 KB
testcase_10 AC 344 ms
28,352 KB
testcase_11 AC 15 ms
7,824 KB
testcase_12 AC 379 ms
28,248 KB
testcase_13 AC 388 ms
28,348 KB
testcase_14 AC 373 ms
28,412 KB
testcase_15 AC 15 ms
7,824 KB
testcase_16 AC 15 ms
7,728 KB
testcase_17 AC 15 ms
7,792 KB
testcase_18 AC 16 ms
7,784 KB
testcase_19 AC 16 ms
7,856 KB
testcase_20 AC 15 ms
7,904 KB
testcase_21 AC 15 ms
7,788 KB
testcase_22 AC 15 ms
7,916 KB
testcase_23 AC 41 ms
9,892 KB
testcase_24 AC 127 ms
15,528 KB
testcase_25 AC 272 ms
23,128 KB
testcase_26 AC 68 ms
11,636 KB
testcase_27 AC 160 ms
19,064 KB
testcase_28 AC 222 ms
21,556 KB
testcase_29 AC 303 ms
23,204 KB
testcase_30 AC 370 ms
27,972 KB
testcase_31 AC 91 ms
13,520 KB
testcase_32 AC 64 ms
11,440 KB
testcase_33 AC 291 ms
23,452 KB
testcase_34 AC 16 ms
7,728 KB
testcase_35 AC 16 ms
7,916 KB
testcase_36 AC 16 ms
7,780 KB
testcase_37 AC 15 ms
7,904 KB
testcase_38 AC 15 ms
7,768 KB
testcase_39 AC 15 ms
7,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Bit:
    """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 = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))

d = {b: i for i, b in enumerate(B, 1)}
X = [d[a] for a in A]

b = Bit(N)
ans = 0
for i, x in enumerate(X):
    ans += i - b.sum(x)
    b.add(x, 1)
print(ans)
0