結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー itsy68itsy68
提出日時 2022-08-24 22:29:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 943 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 82,552 KB
実行使用メモリ 117,364 KB
最終ジャッジ日時 2024-04-20 10:52:36
合計ジャッジ時間 5,109 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
77,780 KB
testcase_01 AC 53 ms
63,140 KB
testcase_02 AC 53 ms
62,600 KB
testcase_03 AC 135 ms
110,468 KB
testcase_04 AC 152 ms
117,072 KB
testcase_05 AC 138 ms
110,120 KB
testcase_06 AC 131 ms
104,724 KB
testcase_07 AC 147 ms
117,364 KB
testcase_08 AC 72 ms
77,644 KB
testcase_09 AC 107 ms
92,940 KB
testcase_10 AC 138 ms
117,352 KB
testcase_11 AC 51 ms
64,356 KB
testcase_12 AC 149 ms
117,104 KB
testcase_13 AC 147 ms
116,892 KB
testcase_14 AC 144 ms
117,216 KB
testcase_15 AC 50 ms
62,792 KB
testcase_16 AC 51 ms
64,616 KB
testcase_17 AC 52 ms
63,036 KB
testcase_18 AC 52 ms
63,768 KB
testcase_19 AC 52 ms
62,856 KB
testcase_20 AC 52 ms
63,592 KB
testcase_21 AC 50 ms
62,712 KB
testcase_22 AC 53 ms
62,920 KB
testcase_23 AC 73 ms
78,168 KB
testcase_24 AC 96 ms
88,652 KB
testcase_25 AC 130 ms
104,556 KB
testcase_26 AC 83 ms
80,796 KB
testcase_27 AC 101 ms
88,380 KB
testcase_28 AC 113 ms
92,856 KB
testcase_29 AC 134 ms
105,588 KB
testcase_30 AC 150 ms
116,044 KB
testcase_31 AC 86 ms
82,840 KB
testcase_32 AC 81 ms
80,240 KB
testcase_33 AC 134 ms
110,536 KB
testcase_34 AC 51 ms
63,408 KB
testcase_35 AC 51 ms
64,280 KB
testcase_36 AC 51 ms
62,716 KB
testcase_37 AC 52 ms
63,756 KB
testcase_38 AC 53 ms
62,896 KB
testcase_39 AC 54 ms
62,988 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[B[i - 1]] = i
C = []
for i in range(N):
    C.append(d[A[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