結果
問題 |
No.1282 Display Elements
|
ユーザー |
![]() |
提出日時 | 2022-11-25 22:56:48 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 304 ms / 2,000 ms |
コード長 | 975 bytes |
コンパイル時間 | 244 ms |
コンパイル使用メモリ | 82,580 KB |
実行使用メモリ | 167,980 KB |
最終ジャッジ日時 | 2024-10-02 05:29:38 |
合計ジャッジ時間 | 4,382 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
class Binary_Indexed_Tree: def __init__(self, n) -> None: self._n = n self.data = [0] * (n+1) self.depth = n.bit_length() def add(self, p, x) -> None: """任意の要素ai←ai+xを行う O(logn)""" assert 0 <= p < self._n p += 1 while p <= self._n: self.data[p-1] += x p += p & (-p) def sum(self, l, r) -> int: """区間[l,r)で計算""" assert 0 <= l <= r <= self._n return self._sum(r) - self._sum(l) def _sum(self, d) -> int: sm = 0 while d > 0: sm += self.data[d-1] d -= d & (-d) return sm N = int(input()) a = list(map(int, input().split())) a.sort() b = list(map(int,input().split())) x_dic = {num:i for i, num in enumerate(list(sorted(set(a+b))))} res = 0 BIT = Binary_Indexed_Tree(len(x_dic)+5) for i in range(N): BIT.add(x_dic[b[i]],1) res += BIT._sum(x_dic[a[i]]) print(res)