Constructor for the Fenwick tree Parameters: arr (list): list of elements to initialize the tree with (optional) size (int): size of the Fenwick tree (if arr is None)
(self, arr: list[int] | None = None, size: int | None = None)
| 9 | """ |
| 10 | |
| 11 | def __init__(self, arr: list[int] | None = None, size: int | None = None) -> None: |
| 12 | """ |
| 13 | Constructor for the Fenwick tree |
| 14 | |
| 15 | Parameters: |
| 16 | arr (list): list of elements to initialize the tree with (optional) |
| 17 | size (int): size of the Fenwick tree (if arr is None) |
| 18 | """ |
| 19 | |
| 20 | if arr is None and size is not None: |
| 21 | self.size = size |
| 22 | self.tree = [0] * size |
| 23 | elif arr is not None: |
| 24 | self.init(arr) |
| 25 | else: |
| 26 | raise ValueError("Either arr or size must be specified") |
| 27 | |
| 28 | def init(self, arr: list[int]) -> None: |
| 29 | """ |