結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー c-yanc-yan
提出日時 2021-03-23 06:21:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 683 ms / 2,000 ms
コード長 840 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 33,148 KB
最終ジャッジ日時 2024-05-03 18:40:00
合計ジャッジ時間 12,042 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
12,288 KB
testcase_01 AC 26 ms
10,752 KB
testcase_02 AC 25 ms
10,624 KB
testcase_03 AC 605 ms
26,632 KB
testcase_04 AC 609 ms
33,108 KB
testcase_05 AC 548 ms
26,700 KB
testcase_06 AC 464 ms
25,564 KB
testcase_07 AC 683 ms
32,960 KB
testcase_08 AC 53 ms
11,648 KB
testcase_09 AC 380 ms
22,668 KB
testcase_10 AC 585 ms
33,116 KB
testcase_11 AC 27 ms
10,624 KB
testcase_12 AC 638 ms
33,148 KB
testcase_13 AC 618 ms
33,120 KB
testcase_14 AC 625 ms
33,100 KB
testcase_15 AC 26 ms
10,752 KB
testcase_16 AC 26 ms
10,752 KB
testcase_17 AC 25 ms
10,624 KB
testcase_18 AC 26 ms
10,752 KB
testcase_19 AC 26 ms
10,752 KB
testcase_20 AC 26 ms
10,752 KB
testcase_21 AC 25 ms
10,624 KB
testcase_22 AC 25 ms
10,752 KB
testcase_23 AC 63 ms
12,288 KB
testcase_24 AC 234 ms
17,908 KB
testcase_25 AC 442 ms
24,912 KB
testcase_26 AC 116 ms
14,208 KB
testcase_27 AC 277 ms
21,344 KB
testcase_28 AC 349 ms
23,468 KB
testcase_29 AC 519 ms
25,752 KB
testcase_30 AC 645 ms
32,820 KB
testcase_31 AC 169 ms
16,176 KB
testcase_32 AC 116 ms
14,336 KB
testcase_33 AC 522 ms
26,784 KB
testcase_34 AC 26 ms
10,624 KB
testcase_35 AC 25 ms
10,752 KB
testcase_36 AC 26 ms
10,624 KB
testcase_37 AC 26 ms
10,752 KB
testcase_38 AC 25 ms
10,624 KB
testcase_39 AC 26 ms
10,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BinaryIndexedTree:
    def __init__(self, size):
        self._data = [0] * size

    def add(self, i, x):
        data = self._data
        i += 1
        n = len(data)
        while i <= n:
            data[i - 1] += x
            i += i & -i

    def _sum(self, stop):
        data = self._data
        result = 0
        i = stop
        while i > 0:
            result += data[i - 1]
            i -= i & -i
        return result

    def range_sum(self, start, stop):
        return self._sum(stop) - self._sum(start)


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

d = {}
for i in range(n):
    d[a[i] - 1] = i
for i in range(n):
    b[i] = d[b[i] - 1]

bit = BinaryIndexedTree(n + 1)

result = 0
for x in b:
    result += bit.range_sum(x + 1, n + 1)
    bit.add(x, 1)
print(result)
0