結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー ttrttr
提出日時 2020-07-17 22:03:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 468 ms / 2,000 ms
コード長 675 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 10,884 KB
実行使用メモリ 23,964 KB
最終ジャッジ日時 2023-08-20 01:17:07
合計ジャッジ時間 8,955 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
9,688 KB
testcase_01 AC 17 ms
7,952 KB
testcase_02 AC 17 ms
7,740 KB
testcase_03 AC 385 ms
21,172 KB
testcase_04 AC 439 ms
23,444 KB
testcase_05 AC 392 ms
21,160 KB
testcase_06 AC 356 ms
20,016 KB
testcase_07 AC 457 ms
23,964 KB
testcase_08 AC 32 ms
9,164 KB
testcase_09 AC 216 ms
17,304 KB
testcase_10 AC 371 ms
23,196 KB
testcase_11 AC 16 ms
7,784 KB
testcase_12 AC 468 ms
23,072 KB
testcase_13 AC 466 ms
23,072 KB
testcase_14 AC 468 ms
23,108 KB
testcase_15 AC 16 ms
7,840 KB
testcase_16 AC 17 ms
7,820 KB
testcase_17 AC 17 ms
7,844 KB
testcase_18 AC 17 ms
7,852 KB
testcase_19 AC 17 ms
7,744 KB
testcase_20 AC 16 ms
7,932 KB
testcase_21 AC 17 ms
7,844 KB
testcase_22 AC 16 ms
7,848 KB
testcase_23 AC 44 ms
9,632 KB
testcase_24 AC 148 ms
14,484 KB
testcase_25 AC 323 ms
20,180 KB
testcase_26 AC 80 ms
11,096 KB
testcase_27 AC 182 ms
15,864 KB
testcase_28 AC 251 ms
18,312 KB
testcase_29 AC 352 ms
20,820 KB
testcase_30 AC 428 ms
22,700 KB
testcase_31 AC 103 ms
12,320 KB
testcase_32 AC 72 ms
10,608 KB
testcase_33 AC 341 ms
21,364 KB
testcase_34 AC 16 ms
7,836 KB
testcase_35 AC 16 ms
7,736 KB
testcase_36 AC 16 ms
7,740 KB
testcase_37 AC 16 ms
7,792 KB
testcase_38 AC 16 ms
7,852 KB
testcase_39 AC 16 ms
7,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]

Bidx = [0]*(N+1)
for i in range(N):
    Bidx[B[i]] = i

for i in range(N):
    B[Bidx[A[i]]] = i+1

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

num = 1
while num <= N:
    num *= 2

bit = Bit(num)
ans = 0

for i, p in enumerate(B):
    bit.add(p, 1)
    ans += i + 1 - bit.sum(p)

print(ans)
0