結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー itsy68itsy68
提出日時 2022-06-10 05:39:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 962 bytes
コンパイル時間 241 ms
コンパイル使用メモリ 81,780 KB
実行使用メモリ 116,240 KB
最終ジャッジ日時 2023-10-21 04:35:58
合計ジャッジ時間 7,399 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
77,268 KB
testcase_01 AC 55 ms
63,348 KB
testcase_02 AC 59 ms
63,348 KB
testcase_03 AC 151 ms
109,780 KB
testcase_04 AC 165 ms
116,240 KB
testcase_05 AC 153 ms
109,504 KB
testcase_06 AC 144 ms
104,064 KB
testcase_07 AC 157 ms
116,240 KB
testcase_08 AC 77 ms
77,076 KB
testcase_09 AC 110 ms
92,120 KB
testcase_10 AC 147 ms
116,240 KB
testcase_11 AC 53 ms
63,348 KB
testcase_12 AC 167 ms
116,240 KB
testcase_13 AC 166 ms
116,240 KB
testcase_14 AC 161 ms
116,240 KB
testcase_15 AC 54 ms
63,348 KB
testcase_16 AC 54 ms
63,348 KB
testcase_17 AC 53 ms
63,348 KB
testcase_18 AC 54 ms
63,348 KB
testcase_19 AC 53 ms
63,348 KB
testcase_20 AC 54 ms
63,348 KB
testcase_21 AC 56 ms
63,348 KB
testcase_22 AC 55 ms
63,348 KB
testcase_23 AC 79 ms
77,284 KB
testcase_24 AC 103 ms
87,868 KB
testcase_25 AC 140 ms
103,724 KB
testcase_26 AC 86 ms
80,340 KB
testcase_27 AC 107 ms
87,904 KB
testcase_28 AC 118 ms
92,172 KB
testcase_29 AC 140 ms
104,644 KB
testcase_30 AC 156 ms
115,184 KB
testcase_31 AC 91 ms
82,372 KB
testcase_32 AC 82 ms
79,240 KB
testcase_33 AC 144 ms
109,860 KB
testcase_34 AC 54 ms
63,348 KB
testcase_35 AC 54 ms
63,348 KB
testcase_36 AC 54 ms
63,348 KB
testcase_37 AC 53 ms
63,348 KB
testcase_38 AC 54 ms
63,348 KB
testcase_39 AC 55 ms
63,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')
import sys
from itertools import combinations, permutations, product, accumulate, groupby
from collections import defaultdict, deque, Counter
from functools import reduce
from operator import add, mul
import heapq
import bisect
import math
import copy

sys.setrecursionlimit(10 ** 9)
input = lambda: sys.stdin.readline().rstrip()
INF = float("inf")
MOD = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
d = {}
for i in range(1, N + 1):
    d[A[i - 1]] = i
C = []
for i in range(N):
    C.append(d[B[i]])
# BIT
data = [0]*(N+1)
def add(k, x):
    while k <= N:
      data[k] += x
      k += k & -k
def get(k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s

ans = 0
for i, a in enumerate(C):
    # 自分より小さい要素がいくつ存在するかを計算
    ans += (N-1-i) - get(a)
    add(a, 1)
print(ans)
0