結果
問題 |
No.1604 Swap Sort:ONE
|
ユーザー |
![]() |
提出日時 | 2021-07-16 23:46:02 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 36 ms / 2,000 ms |
コード長 | 703 bytes |
コンパイル時間 | 87 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-07-06 11:21:46 |
合計ジャッジ時間 | 1,673 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
class BinaryIndexedTree: def __init__(self, size): self._data = [0] * size def add(self, i, x): data = self._data i += 1 n = len(data) while i <= n: data[i - 1] += x i += i & -i def _sum(self, stop): data = self._data result = 0 i = stop while i > 0: result += data[i - 1] i -= i & -i return result def range_sum(self, start, stop): return self._sum(stop) - self._sum(start) N, *P = map(int, open(0).read().split()) bit = BinaryIndexedTree(N + 1) result = 0 for x in P: result += bit.range_sum(x + 1, N + 1) bit.add(x, 1) print(result)