結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー anagohirameanagohirame
提出日時 2020-07-17 22:59:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 595 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 86,952 KB
実行使用メモリ 101,784 KB
最終ジャッジ日時 2023-08-20 02:58:21
合計ジャッジ時間 6,396 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
77,516 KB
testcase_01 AC 68 ms
71,284 KB
testcase_02 AC 68 ms
71,320 KB
testcase_03 AC 134 ms
98,444 KB
testcase_04 AC 141 ms
100,628 KB
testcase_05 AC 136 ms
101,280 KB
testcase_06 AC 136 ms
99,992 KB
testcase_07 AC 146 ms
101,400 KB
testcase_08 AC 88 ms
76,524 KB
testcase_09 AC 115 ms
93,648 KB
testcase_10 AC 139 ms
101,476 KB
testcase_11 AC 69 ms
71,280 KB
testcase_12 AC 141 ms
101,620 KB
testcase_13 AC 147 ms
101,784 KB
testcase_14 AC 148 ms
101,628 KB
testcase_15 AC 71 ms
71,216 KB
testcase_16 AC 71 ms
71,300 KB
testcase_17 AC 71 ms
71,252 KB
testcase_18 AC 70 ms
71,216 KB
testcase_19 AC 70 ms
71,180 KB
testcase_20 AC 70 ms
71,276 KB
testcase_21 AC 70 ms
71,444 KB
testcase_22 AC 71 ms
71,456 KB
testcase_23 AC 88 ms
77,532 KB
testcase_24 AC 103 ms
84,600 KB
testcase_25 AC 131 ms
99,604 KB
testcase_26 AC 94 ms
78,716 KB
testcase_27 AC 108 ms
88,184 KB
testcase_28 AC 121 ms
93,996 KB
testcase_29 AC 132 ms
99,812 KB
testcase_30 AC 142 ms
101,416 KB
testcase_31 AC 99 ms
80,920 KB
testcase_32 AC 94 ms
78,200 KB
testcase_33 AC 134 ms
98,440 KB
testcase_34 AC 71 ms
71,056 KB
testcase_35 AC 70 ms
71,328 KB
testcase_36 AC 70 ms
71,184 KB
testcase_37 AC 69 ms
71,276 KB
testcase_38 AC 70 ms
71,280 KB
testcase_39 AC 72 ms
71,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT():#1-indexed
	def __init__(self, size):
		self.table = [0 for _ in range(size+2)]
		self.size = size

	def Sum(self, i):#1からiまでの和
		s = 0
		while i > 0:
			s += self.table[i]
			i -= (i & -i)
		return s

	def PointAdd(self, i, x):#
		while i <= self.size:
			self.table[i] += x
			i += (i & -i)
		return

n = int(input())
a = list(map(int, input().split()))
p = [-1 for _ in range(n+1)]
for i, x in enumerate(a):
	p[x] = i+1
b = list(map(int, input().split()))
q = [p[x] for x in b]
ans = 0
bit = BIT(n+1)
for x in q[::-1]:
	ans += bit.Sum(x)
	bit.PointAdd(x, 1)
print(ans)
0