結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー mkawa2mkawa2
提出日時 2020-07-17 21:59:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 409 ms / 2,000 ms
コード長 1,312 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 11,104 KB
実行使用メモリ 30,132 KB
最終ジャッジ日時 2023-08-20 01:04:41
合計ジャッジ時間 8,632 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
11,676 KB
testcase_01 AC 30 ms
9,860 KB
testcase_02 AC 31 ms
9,988 KB
testcase_03 AC 343 ms
24,900 KB
testcase_04 AC 393 ms
30,040 KB
testcase_05 AC 332 ms
24,288 KB
testcase_06 AC 315 ms
22,976 KB
testcase_07 AC 386 ms
30,132 KB
testcase_08 AC 44 ms
10,944 KB
testcase_09 AC 204 ms
21,316 KB
testcase_10 AC 352 ms
29,312 KB
testcase_11 AC 30 ms
9,948 KB
testcase_12 AC 409 ms
29,380 KB
testcase_13 AC 398 ms
29,176 KB
testcase_14 AC 394 ms
29,276 KB
testcase_15 AC 30 ms
9,864 KB
testcase_16 AC 29 ms
9,920 KB
testcase_17 AC 30 ms
9,924 KB
testcase_18 AC 30 ms
9,856 KB
testcase_19 AC 31 ms
10,036 KB
testcase_20 AC 30 ms
10,036 KB
testcase_21 AC 31 ms
10,000 KB
testcase_22 AC 29 ms
9,996 KB
testcase_23 AC 55 ms
11,756 KB
testcase_24 AC 148 ms
17,248 KB
testcase_25 AC 300 ms
23,436 KB
testcase_26 AC 85 ms
13,324 KB
testcase_27 AC 177 ms
21,228 KB
testcase_28 AC 231 ms
21,868 KB
testcase_29 AC 314 ms
24,648 KB
testcase_30 AC 372 ms
29,268 KB
testcase_31 AC 105 ms
15,476 KB
testcase_32 AC 76 ms
13,296 KB
testcase_33 AC 309 ms
23,292 KB
testcase_34 AC 29 ms
9,968 KB
testcase_35 AC 30 ms
9,980 KB
testcase_36 AC 30 ms
9,928 KB
testcase_37 AC 30 ms
10,068 KB
testcase_38 AC 30 ms
9,948 KB
testcase_39 AC 29 ms
10,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from operator import itemgetter
from itertools import *
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction
import sys

sys.setrecursionlimit(10 ** 6)

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

class BitSum:
    def __init__(self, n):
        self.n = n + 1
        self.table = [0] * self.n

    def add(self, i, x):
        i += 1
        while i < self.n:
            self.table[i] += x
            i += i & -i

    def sum(self, i):
        i += 1
        res = 0
        while i > 0:
            res += self.table[i]
            i -= i & -i
        return res

n=II()
aa=LI()
bb=LI()
atoi={b:i for i,b in enumerate(bb)}
aa=[atoi[a] for a in aa]
bit=BitSum(n)
ans=0
for i,a in enumerate(aa):
    ans+=i-bit.sum(a)
    bit.add(a,1)
print(ans)
0