結果
問題 | No.1115 二つの数列 / Two Sequences |
ユーザー |
![]() |
提出日時 | 2020-07-17 21:33:37 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 459 ms / 2,000 ms |
コード長 | 623 bytes |
コンパイル時間 | 115 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 30,712 KB |
最終ジャッジ日時 | 2024-11-29 21:59:52 |
合計ジャッジ時間 | 8,579 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 35 |
ソースコード
class BinaryIndexTree: # 1-indexeddef __init__(self, n):self.size = nself.tree = [0] * (n + 1)def sum(self, i):s = 0while i > 0:s += self.tree[i]i -= i & -ireturn sdef add(self, i, x):while i <= self.size:self.tree[i] += xi += i & -iN = int(input())A = list(map(int, input().split()))B = list(map(int, input().split()))btoi = {b: i for i, b in enumerate(B, 1)}ans = 0bit = BinaryIndexTree(N + 1)for i, a in enumerate(A):ans += i - bit.sum(btoi[a])bit.add(btoi[a], 1)print(ans)