結果
| 問題 | No.1115 二つの数列 / Two Sequences |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-06-10 05:39:11 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 104 ms / 2,000 ms |
| コード長 | 962 bytes |
| 記録 | |
| コンパイル時間 | 164 ms |
| コンパイル使用メモリ | 85,376 KB |
| 実行使用メモリ | 115,328 KB |
| 最終ジャッジ日時 | 2026-04-09 13:01:29 |
| 合計ジャッジ時間 | 4,981 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 35 |
ソースコード
# 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)