結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー roarisroaris
提出日時 2020-07-24 22:17:25
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 224 ms / 2,000 ms
コード長 693 bytes
コンパイル時間 1,031 ms
コンパイル使用メモリ 86,816 KB
実行使用メモリ 121,224 KB
最終ジャッジ日時 2023-09-08 04:30:32
合計ジャッジ時間 7,952 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
78,004 KB
testcase_01 AC 94 ms
71,360 KB
testcase_02 AC 94 ms
71,516 KB
testcase_03 AC 199 ms
115,400 KB
testcase_04 AC 214 ms
121,064 KB
testcase_05 AC 211 ms
115,404 KB
testcase_06 AC 186 ms
110,916 KB
testcase_07 AC 212 ms
121,064 KB
testcase_08 AC 111 ms
77,976 KB
testcase_09 AC 155 ms
102,620 KB
testcase_10 AC 186 ms
121,140 KB
testcase_11 AC 91 ms
71,656 KB
testcase_12 AC 223 ms
121,224 KB
testcase_13 AC 224 ms
121,188 KB
testcase_14 AC 213 ms
121,124 KB
testcase_15 AC 91 ms
71,168 KB
testcase_16 AC 93 ms
71,420 KB
testcase_17 AC 93 ms
71,720 KB
testcase_18 AC 93 ms
71,604 KB
testcase_19 AC 93 ms
71,356 KB
testcase_20 AC 93 ms
71,572 KB
testcase_21 AC 95 ms
71,656 KB
testcase_22 AC 92 ms
71,336 KB
testcase_23 AC 111 ms
77,960 KB
testcase_24 AC 138 ms
89,624 KB
testcase_25 AC 181 ms
110,444 KB
testcase_26 AC 122 ms
81,816 KB
testcase_27 AC 151 ms
94,900 KB
testcase_28 AC 168 ms
102,376 KB
testcase_29 AC 191 ms
110,868 KB
testcase_30 AC 206 ms
120,440 KB
testcase_31 AC 128 ms
84,428 KB
testcase_32 AC 124 ms
80,664 KB
testcase_33 AC 180 ms
115,264 KB
testcase_34 AC 97 ms
71,720 KB
testcase_35 AC 94 ms
71,496 KB
testcase_36 AC 92 ms
71,416 KB
testcase_37 AC 91 ms
71,644 KB
testcase_38 AC 92 ms
71,540 KB
testcase_39 AC 93 ms
71,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)
    
    def add(self, i, x):
        i += 1
        
        while i<=self.n:
            self.bit[i] += x
            i += i&(-i)
            
    def acc(self, i):
        s = 0
        
        while i>0:
            s += self.bit[i]
            i -= i&(-i)
        
        return s

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = defaultdict(int)

for i in range(n):
    d[b[i]] = i

bit = BIT(n)
ans = 0

for i in range(n):
    ans += i-bit.acc(d[a[i]])
    bit.add(d[a[i]], 1)

print(ans)
0