結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-03-08 13:26:23
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 960 bytes
コンパイル時間 326 ms
コンパイル使用メモリ 86,948 KB
実行使用メモリ 103,804 KB
最終ジャッジ日時 2023-09-30 19:12:14
合計ジャッジ時間 6,696 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
77,556 KB
testcase_01 AC 78 ms
71,544 KB
testcase_02 AC 77 ms
71,176 KB
testcase_03 AC 147 ms
101,192 KB
testcase_04 AC 153 ms
100,536 KB
testcase_05 AC 143 ms
101,644 KB
testcase_06 AC 139 ms
99,480 KB
testcase_07 AC 151 ms
100,460 KB
testcase_08 AC 89 ms
76,776 KB
testcase_09 AC 125 ms
93,376 KB
testcase_10 AC 146 ms
100,824 KB
testcase_11 AC 74 ms
71,336 KB
testcase_12 AC 150 ms
100,720 KB
testcase_13 AC 157 ms
100,832 KB
testcase_14 AC 152 ms
100,552 KB
testcase_15 AC 76 ms
71,336 KB
testcase_16 AC 73 ms
71,176 KB
testcase_17 AC 75 ms
71,244 KB
testcase_18 AC 75 ms
71,252 KB
testcase_19 AC 73 ms
71,516 KB
testcase_20 AC 76 ms
71,176 KB
testcase_21 AC 75 ms
71,356 KB
testcase_22 AC 75 ms
71,172 KB
testcase_23 AC 93 ms
77,504 KB
testcase_24 AC 110 ms
84,336 KB
testcase_25 AC 138 ms
99,152 KB
testcase_26 AC 98 ms
78,980 KB
testcase_27 AC 116 ms
87,732 KB
testcase_28 AC 128 ms
93,468 KB
testcase_29 AC 139 ms
99,632 KB
testcase_30 AC 150 ms
103,804 KB
testcase_31 AC 105 ms
80,320 KB
testcase_32 AC 99 ms
78,012 KB
testcase_33 AC 146 ms
101,176 KB
testcase_34 AC 75 ms
71,428 KB
testcase_35 AC 75 ms
71,040 KB
testcase_36 AC 76 ms
71,028 KB
testcase_37 AC 76 ms
71,320 KB
testcase_38 AC 79 ms
71,308 KB
testcase_39 AC 76 ms
71,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
 
    def build(self, list):
        self.tree[1:] = list.copy()
        for i in range(self.size+1):
            j = i + (i & (-i))
            if j < self.size+1:
                self.tree[j] += self.tree[i]

    def sum(self, i):
        # [0, i) の要素の総和を返す
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s
    # 0 index を 1 index に変更  転倒数を求めるなら1を足していく
    def add(self, i, x):
        i += 1
        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()))
id = [-1]*(n+1)
for i,b in enumerate(B):
    id[b] = i

iA = [id[a] for a in A]

bit = BIT(n+5)
ans = 0
for i,a in enumerate(iA):
    s = bit.sum(a)
    ans += i-s
    bit.add(a,1)
print(ans)
0