結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー convexineqconvexineq
提出日時 2021-05-10 05:20:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 714 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 81,824 KB
実行使用メモリ 104,412 KB
最終ジャッジ日時 2023-10-19 13:05:30
合計ジャッジ時間 5,917 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
75,916 KB
testcase_01 AC 35 ms
53,528 KB
testcase_02 AC 39 ms
53,528 KB
testcase_03 AC 116 ms
104,412 KB
testcase_04 AC 118 ms
101,484 KB
testcase_05 AC 107 ms
103,088 KB
testcase_06 AC 114 ms
100,804 KB
testcase_07 AC 116 ms
101,472 KB
testcase_08 AC 51 ms
72,688 KB
testcase_09 AC 88 ms
94,104 KB
testcase_10 AC 118 ms
101,772 KB
testcase_11 AC 36 ms
53,528 KB
testcase_12 AC 120 ms
101,772 KB
testcase_13 AC 118 ms
101,772 KB
testcase_14 AC 121 ms
101,772 KB
testcase_15 AC 35 ms
53,528 KB
testcase_16 AC 34 ms
53,528 KB
testcase_17 AC 35 ms
53,528 KB
testcase_18 AC 34 ms
53,528 KB
testcase_19 AC 35 ms
53,528 KB
testcase_20 AC 34 ms
53,528 KB
testcase_21 AC 34 ms
53,528 KB
testcase_22 AC 35 ms
53,528 KB
testcase_23 AC 60 ms
75,932 KB
testcase_24 AC 73 ms
84,288 KB
testcase_25 AC 100 ms
100,628 KB
testcase_26 AC 62 ms
77,932 KB
testcase_27 AC 78 ms
87,772 KB
testcase_28 AC 90 ms
94,416 KB
testcase_29 AC 103 ms
100,816 KB
testcase_30 AC 116 ms
101,688 KB
testcase_31 AC 66 ms
79,828 KB
testcase_32 AC 60 ms
76,712 KB
testcase_33 AC 108 ms
103,640 KB
testcase_34 AC 36 ms
53,528 KB
testcase_35 AC 36 ms
53,528 KB
testcase_36 AC 35 ms
53,528 KB
testcase_37 AC 35 ms
53,528 KB
testcase_38 AC 35 ms
53,528 KB
testcase_39 AC 35 ms
53,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT: #0-indexed
    def __init__(self, n):
        self.tree = [0]*(n+1)
    def sum(self, i): #a_0 + ... + a_{i} #閉区間
        s = 0; i += 1
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
    def range(self,l,r): #a_l + ... + a_r 閉区間
        return sum(r) - sum(l-1) 
    def add(self, i, x):
        i += 1
        while i <= n:
            self.tree[i] += x
            i += i & -i

n = int(input())
*a, = map(int,input().split())
*b, = map(int,input().split())
r = [0]*n
for i in range(n):
    r[a[i]-1] = i
for i in range(n):
    b[i] = r[b[i]-1]
bit = BIT(n)
ans = 0
for i,bi in enumerate(b):
    ans += i-bit.sum(bi)
    bit.add(bi,1)
print(ans)
0