結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー itsy68itsy68
提出日時 2022-09-20 21:01:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 974 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 87,112 KB
実行使用メモリ 127,544 KB
最終ジャッジ日時 2023-08-23 19:39:56
合計ジャッジ時間 10,254 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 145 ms
80,764 KB
testcase_01 AC 123 ms
77,092 KB
testcase_02 AC 120 ms
76,884 KB
testcase_03 AC 214 ms
121,116 KB
testcase_04 AC 224 ms
127,452 KB
testcase_05 AC 211 ms
120,968 KB
testcase_06 AC 202 ms
109,480 KB
testcase_07 AC 225 ms
126,884 KB
testcase_08 AC 139 ms
80,588 KB
testcase_09 AC 182 ms
103,456 KB
testcase_10 AC 215 ms
127,544 KB
testcase_11 AC 118 ms
76,900 KB
testcase_12 AC 225 ms
126,952 KB
testcase_13 AC 227 ms
127,044 KB
testcase_14 AC 225 ms
127,296 KB
testcase_15 AC 121 ms
77,064 KB
testcase_16 AC 120 ms
76,848 KB
testcase_17 AC 120 ms
77,000 KB
testcase_18 AC 118 ms
76,764 KB
testcase_19 AC 119 ms
76,884 KB
testcase_20 AC 119 ms
77,036 KB
testcase_21 AC 120 ms
77,048 KB
testcase_22 AC 119 ms
77,216 KB
testcase_23 AC 141 ms
80,880 KB
testcase_24 AC 163 ms
90,968 KB
testcase_25 AC 197 ms
108,900 KB
testcase_26 AC 150 ms
82,880 KB
testcase_27 AC 176 ms
96,180 KB
testcase_28 AC 184 ms
102,452 KB
testcase_29 AC 201 ms
109,396 KB
testcase_30 AC 222 ms
126,592 KB
testcase_31 AC 152 ms
85,728 KB
testcase_32 AC 147 ms
82,232 KB
testcase_33 AC 208 ms
121,216 KB
testcase_34 AC 121 ms
77,016 KB
testcase_35 AC 121 ms
77,044 KB
testcase_36 AC 123 ms
77,076 KB
testcase_37 AC 122 ms
76,912 KB
testcase_38 AC 122 ms
77,076 KB
testcase_39 AC 122 ms
77,104 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')

#https://tjkendev.github.io/procon-library/python/sequence/number_of_inversions.html
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
d = {}
for i in range(N):
    d[B[i]] = i + 1
adjustedA = []
for i in range(N):
    adjustedA.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(adjustedA):
    ans += (N - 1 - i) - get(a)
    add(a, 1)
print(ans)
0