結果

問題 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  
実行時間 607 ms / 2,000 ms
コード長 840 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 10,836 KB
実行使用メモリ 30,484 KB
最終ジャッジ日時 2023-08-16 09:59:56
合計ジャッジ時間 13,669 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
9,952 KB
testcase_01 AC 17 ms
7,856 KB
testcase_02 AC 16 ms
7,816 KB
testcase_03 AC 528 ms
24,388 KB
testcase_04 AC 579 ms
30,332 KB
testcase_05 AC 485 ms
24,256 KB
testcase_06 AC 405 ms
23,036 KB
testcase_07 AC 607 ms
30,484 KB
testcase_08 AC 38 ms
9,368 KB
testcase_09 AC 323 ms
21,516 KB
testcase_10 AC 500 ms
30,404 KB
testcase_11 AC 16 ms
7,832 KB
testcase_12 AC 560 ms
30,392 KB
testcase_13 AC 560 ms
30,456 KB
testcase_14 AC 557 ms
30,368 KB
testcase_15 AC 15 ms
7,844 KB
testcase_16 AC 15 ms
7,836 KB
testcase_17 AC 15 ms
7,760 KB
testcase_18 AC 15 ms
7,816 KB
testcase_19 AC 16 ms
7,832 KB
testcase_20 AC 15 ms
7,860 KB
testcase_21 AC 15 ms
7,788 KB
testcase_22 AC 15 ms
7,924 KB
testcase_23 AC 50 ms
9,904 KB
testcase_24 AC 194 ms
16,272 KB
testcase_25 AC 394 ms
23,208 KB
testcase_26 AC 96 ms
11,784 KB
testcase_27 AC 237 ms
19,184 KB
testcase_28 AC 304 ms
21,464 KB
testcase_29 AC 455 ms
23,144 KB
testcase_30 AC 549 ms
30,196 KB
testcase_31 AC 139 ms
13,640 KB
testcase_32 AC 93 ms
11,460 KB
testcase_33 AC 439 ms
24,764 KB
testcase_34 AC 15 ms
7,856 KB
testcase_35 AC 16 ms
7,844 KB
testcase_36 AC 15 ms
7,768 KB
testcase_37 AC 15 ms
7,812 KB
testcase_38 AC 16 ms
7,828 KB
testcase_39 AC 16 ms
7,968 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