結果
| 問題 | No.1282 Display Elements |
| コンテスト | |
| ユーザー |
koheijkt
|
| 提出日時 | 2026-04-06 18:45:40 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,066 bytes |
| 記録 | |
| コンパイル時間 | 128 ms |
| コンパイル使用メモリ | 85,376 KB |
| 実行使用メモリ | 184,196 KB |
| 最終ジャッジ日時 | 2026-04-06 18:45:48 |
| 合計ジャッジ時間 | 3,042 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 RE * 9 |
ソースコード
import typing
class FenwickTree:
'''Reference: https://en.wikipedia.org/wiki/Fenwick_tree'''
def __init__(self, n: int = 0) -> None:
self._n = n
self.data = [0] * n
def add(self, p: int, x: typing.Any) -> None:
assert 0 <= p < self._n
p += 1
while p <= self._n:
self.data[p - 1] += x
p += p & -p
def sum(self, left: int, right: int) -> typing.Any:
assert 0 <= left <= right <= self._n
return self._sum(right) - self._sum(left)
def _sum(self, r: int) -> typing.Any:
s = 0
while r > 0:
s += self.data[r - 1]
r -= r & -r
return s
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
d = {}
id = 0
for num in sorted(set(A) | set(B)):
d[num] = id
id += 1
A.sort()
ft = FenwickTree(N + 10)
ans = 0
for i in range(N):
# Bのターン
b = B[i]
ft.add(d[b], 1)
# Aのターン
a = d[A[i]]
# a 未満の数を計上
ans += ft.sum(0, a)
print(ans)
koheijkt