結果
問題 | No.1282 Display Elements |
ユーザー |
![]() |
提出日時 | 2025-01-21 21:02:55 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 331 ms / 2,000 ms |
コード長 | 974 bytes |
コンパイル時間 | 315 ms |
コンパイル使用メモリ | 82,728 KB |
実行使用メモリ | 169,856 KB |
最終ジャッジ日時 | 2025-01-21 21:03:01 |
合計ジャッジ時間 | 5,243 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
import typingclass FenwickTree:'''Reference: https://en.wikipedia.org/wiki/Fenwick_tree'''def __init__(self, n: int = 0) -> None:self._n = nself.data = [0] * ndef add(self, p: int, x: typing.Any) -> None:assert 0 <= p < self._np += 1while p <= self._n:self.data[p - 1] += xp += p & -pdef sum(self, left: int, right: int) -> typing.Any:assert 0 <= left <= right <= self._nreturn self._sum(right) - self._sum(left)def _sum(self, r: int) -> typing.Any:s = 0while r > 0:s += self.data[r - 1]r -= r & -rreturn sN = int(input())A = list(map(int, input().split()))B = list(map(int, input().split()))C = A + BC = sorted(list(set(C)))NC = len(C)dic = dict(zip(C, range(NC)))A.sort()ft = FenwickTree(NC)ans = 0for i in range(N):ft.add(dic[B[i]],1)ans += ft.sum(0, dic[A[i]])print(ans)