結果
問題 | No.1115 二つの数列 / Two Sequences |
ユーザー |
👑 |
提出日時 | 2022-07-04 15:38:18 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 140 ms / 2,000 ms |
コード長 | 1,136 bytes |
コンパイル時間 | 285 ms |
コンパイル使用メモリ | 82,520 KB |
実行使用メモリ | 105,740 KB |
最終ジャッジ日時 | 2024-12-14 06:11:30 |
合計ジャッジ時間 | 6,087 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 35 |
ソースコード
class Bit:def __init__(self, n):self.size = nself.n0 = 1 << (n.bit_length() - 1)self.tree = [0] * (n + 1)def range_sum(self, l, r):return self.sum(r - 1) - self.sum(l - 1)def sum(self, i):i += 1s = 0while i > 0:s += self.tree[i]i -= i & -ireturn sdef get(self, i):return self.sum(i) - self.sum(i - 1)def add(self, i, x):i += 1while i <= self.size:self.tree[i] += xi += i & -idef lower_bound(self, x):pos = 0plus = self.n0while plus > 0:if pos + plus <= self.size and self.tree[pos + plus] < x:x -= self.tree[pos + plus]pos += plusplus //= 2return posn = int(input())A = list(map(int, input().split()))B = list(map(int, input().split()))inv = [0] * (n + 1)for i, a in enumerate(A):inv[a] = iB = [inv[b] for b in B]ans = 0bit = Bit(n)for b in B:ans += bit.range_sum(b + 1, n)bit.add(b, 1)print(ans)