結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー 👑 H20H20
提出日時 2021-02-03 10:52:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 640 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 104,988 KB
最終ジャッジ日時 2023-09-12 11:48:10
合計ジャッジ時間 8,206 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
77,688 KB
testcase_01 AC 73 ms
71,216 KB
testcase_02 AC 74 ms
71,108 KB
testcase_03 AC 158 ms
100,020 KB
testcase_04 AC 169 ms
104,972 KB
testcase_05 AC 156 ms
100,428 KB
testcase_06 AC 148 ms
97,972 KB
testcase_07 AC 170 ms
104,988 KB
testcase_08 AC 89 ms
76,704 KB
testcase_09 AC 135 ms
101,928 KB
testcase_10 AC 164 ms
104,884 KB
testcase_11 AC 71 ms
71,064 KB
testcase_12 AC 170 ms
104,864 KB
testcase_13 AC 173 ms
104,836 KB
testcase_14 AC 173 ms
104,768 KB
testcase_15 AC 74 ms
71,140 KB
testcase_16 AC 72 ms
71,132 KB
testcase_17 AC 73 ms
71,140 KB
testcase_18 AC 72 ms
71,000 KB
testcase_19 AC 73 ms
71,340 KB
testcase_20 AC 73 ms
71,256 KB
testcase_21 AC 73 ms
71,188 KB
testcase_22 AC 72 ms
71,244 KB
testcase_23 AC 91 ms
77,496 KB
testcase_24 AC 116 ms
88,188 KB
testcase_25 AC 148 ms
99,912 KB
testcase_26 AC 102 ms
80,796 KB
testcase_27 AC 122 ms
93,596 KB
testcase_28 AC 140 ms
102,136 KB
testcase_29 AC 148 ms
97,796 KB
testcase_30 AC 163 ms
103,224 KB
testcase_31 AC 106 ms
83,076 KB
testcase_32 AC 100 ms
79,592 KB
testcase_33 AC 149 ms
100,352 KB
testcase_34 AC 72 ms
71,252 KB
testcase_35 AC 72 ms
71,432 KB
testcase_36 AC 72 ms
71,152 KB
testcase_37 AC 71 ms
71,372 KB
testcase_38 AC 72 ms
71,360 KB
testcase_39 AC 72 ms
71,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Bit:
    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()))
d = {}
for i in range(N):
    d[B[i]]=i+1
for i in range(N):
    A[i] = d[A[i]]

bit = Bit(N+1)
ans = 0
for i in range(N):
    A[i]+=1

for i in range(N):
    bit.add(A[i], 1)
    ans += i + 1 - bit.sum(A[i])
print(ans)
0