結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー itsy68itsy68
提出日時 2022-08-24 22:26:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 176 ms / 2,000 ms
コード長 943 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 82,072 KB
実行使用メモリ 117,164 KB
最終ジャッジ日時 2024-04-20 10:50:02
合計ジャッジ時間 6,606 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
77,824 KB
testcase_01 AC 56 ms
62,848 KB
testcase_02 AC 57 ms
62,208 KB
testcase_03 AC 152 ms
110,208 KB
testcase_04 AC 176 ms
117,164 KB
testcase_05 AC 158 ms
110,248 KB
testcase_06 AC 147 ms
104,576 KB
testcase_07 AC 162 ms
117,148 KB
testcase_08 AC 77 ms
77,184 KB
testcase_09 AC 115 ms
92,544 KB
testcase_10 AC 155 ms
117,120 KB
testcase_11 AC 57 ms
62,848 KB
testcase_12 AC 166 ms
116,736 KB
testcase_13 AC 169 ms
116,964 KB
testcase_14 AC 167 ms
116,992 KB
testcase_15 AC 56 ms
62,208 KB
testcase_16 AC 56 ms
62,592 KB
testcase_17 AC 56 ms
62,848 KB
testcase_18 AC 60 ms
62,080 KB
testcase_19 AC 58 ms
62,592 KB
testcase_20 AC 57 ms
62,848 KB
testcase_21 AC 57 ms
62,208 KB
testcase_22 AC 57 ms
61,952 KB
testcase_23 AC 80 ms
77,440 KB
testcase_24 AC 106 ms
88,320 KB
testcase_25 AC 139 ms
104,448 KB
testcase_26 AC 87 ms
81,112 KB
testcase_27 AC 109 ms
88,704 KB
testcase_28 AC 122 ms
92,672 KB
testcase_29 AC 146 ms
105,088 KB
testcase_30 AC 162 ms
116,152 KB
testcase_31 AC 95 ms
82,816 KB
testcase_32 AC 100 ms
79,488 KB
testcase_33 AC 148 ms
110,528 KB
testcase_34 AC 57 ms
62,208 KB
testcase_35 AC 59 ms
62,592 KB
testcase_36 AC 63 ms
61,952 KB
testcase_37 AC 62 ms
62,592 KB
testcase_38 AC 56 ms
62,464 KB
testcase_39 AC 57 ms
61,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import combinations, permutations, product, accumulate, groupby
from collections import defaultdict, deque, Counter
from functools import reduce
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
# DFS
# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
d = dict()
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