結果
問題 | No.1115 二つの数列 / Two Sequences |
ユーザー |
![]() |
提出日時 | 2023-02-01 01:27:36 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 161 ms / 2,000 ms |
コード長 | 1,126 bytes |
コンパイル時間 | 145 ms |
コンパイル使用メモリ | 82,416 KB |
実行使用メモリ | 109,388 KB |
最終ジャッジ日時 | 2024-07-01 00:49:43 |
合計ジャッジ時間 | 5,970 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 35 |
ソースコード
class Fenwick_Tree:def __init__(self, n):self._n = nself.data = [0] * ndef add(self, p, x):assert 0 <= p < self._np += 1while p <= self._n:self.data[p - 1] += xp += p & -pdef sum(self, l, r):assert 0 <= l <= r <= self._nreturn self._sum(r) - self._sum(l)def _sum(self, r):s = 0while r > 0:s += self.data[r - 1]r -= r & -rreturn sdef get(self, k):k += 1x, r = 0, 1while r < self._n:r <<= 1len = rwhile len:if x + len - 1 < self._n:if self.data[x + len - 1] < k:k -= self.data[x + len - 1]x += lenlen >>= 1return xN = int(input())A = list(map(int, input().split()))B = list(map(int, input().split()))D = dict()for i, b in enumerate(B):D[b] = ifor i in range(N):A[i] = D[A[i]]ans = 0T = Fenwick_Tree(101010)for a in A:ans += T.sum(a + 1, 101010)T.add(a, 1)print(ans)