結果
問題 | No.1115 二つの数列 / Two Sequences |
ユーザー |
|
提出日時 | 2020-07-17 21:35:58 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 515 ms / 2,000 ms |
コード長 | 606 bytes |
コンパイル時間 | 257 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 30,692 KB |
最終ジャッジ日時 | 2024-11-29 22:13:01 |
合計ジャッジ時間 | 9,602 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 35 |
ソースコード
class Bit: """1-indexed""" def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i N = int(input()) A = tuple(map(int, input().split())) B = tuple(map(int, input().split())) d = {b: i for i, b in enumerate(B, 1)} X = [d[a] for a in A] b = Bit(N) ans = 0 for i, x in enumerate(X): ans += i - b.sum(x) b.add(x, 1) print(ans)