結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー itsy68itsy68
提出日時 2022-09-20 21:03:50
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 970 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 86,868 KB
実行使用メモリ 89,456 KB
最終ジャッジ日時 2023-08-23 19:40:04
合計ジャッジ時間 7,042 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

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
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