結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー irumo8202irumo8202
提出日時 2022-01-26 17:18:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 792 bytes
コンパイル時間 528 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 104,172 KB
最終ジャッジ日時 2023-08-24 22:51:11
合計ジャッジ時間 8,959 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
77,340 KB
testcase_01 AC 70 ms
71,128 KB
testcase_02 AC 71 ms
71,344 KB
testcase_03 AC 143 ms
101,180 KB
testcase_04 AC 153 ms
100,300 KB
testcase_05 AC 143 ms
101,184 KB
testcase_06 AC 139 ms
99,004 KB
testcase_07 AC 150 ms
100,380 KB
testcase_08 AC 88 ms
76,384 KB
testcase_09 AC 120 ms
92,784 KB
testcase_10 AC 142 ms
100,828 KB
testcase_11 AC 71 ms
71,328 KB
testcase_12 AC 153 ms
100,376 KB
testcase_13 AC 154 ms
100,372 KB
testcase_14 AC 151 ms
100,608 KB
testcase_15 AC 71 ms
71,240 KB
testcase_16 AC 72 ms
71,260 KB
testcase_17 AC 72 ms
71,344 KB
testcase_18 AC 71 ms
71,296 KB
testcase_19 AC 71 ms
71,380 KB
testcase_20 AC 71 ms
71,312 KB
testcase_21 AC 70 ms
71,224 KB
testcase_22 AC 71 ms
71,276 KB
testcase_23 AC 90 ms
77,292 KB
testcase_24 AC 108 ms
84,516 KB
testcase_25 AC 137 ms
98,248 KB
testcase_26 AC 97 ms
78,684 KB
testcase_27 AC 114 ms
87,636 KB
testcase_28 AC 125 ms
92,840 KB
testcase_29 AC 137 ms
98,856 KB
testcase_30 AC 151 ms
104,172 KB
testcase_31 AC 100 ms
80,700 KB
testcase_32 AC 95 ms
77,788 KB
testcase_33 AC 145 ms
101,516 KB
testcase_34 AC 71 ms
71,312 KB
testcase_35 AC 71 ms
71,168 KB
testcase_36 AC 70 ms
71,172 KB
testcase_37 AC 73 ms
71,220 KB
testcase_38 AC 71 ms
71,148 KB
testcase_39 AC 70 ms
71,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


class Fenwick_Tree:
    def __init__(self, n):
        self._n = n
        self.data = [0] * n

    def add(self, p, x):
        assert 0 <= p < self._n
        p += 1
        while p <= self._n:
            self.data[p - 1] += x
            p += p & -p

    def sum(self, l, r):
        assert 0 <= l <= r <= self._n
        return self._sum(r) - self._sum(l)

    def _sum(self, r):
        s = 0
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r
        return s


ind = [-1] * (N + 1)
for i, b in enumerate(B, 1):
    ind[b] = i

bit = Fenwick_Tree(N + 1)
ans = 0
for i, a in enumerate(A):
    id = ind[a]
    ans += i - bit.sum(0, id)
    bit.add(id, 1)


print(ans)
0