Segment Tree
Data structure for arrays of monoids that supports:
- point update:
- range query: find
- lower bound: given and , find the largest such that .
__init__
Arguments
A: list[T]: array of monoiddot: Callable[[T, T], T]: binary operator corresponding toe: T: identity element corresponding to
Complexities
- time:
- space:
where represents the length of A.
__getitem__
Returns the i-th element of the array.
Arguments
i: int: index
Returns
T: element at indexi
Complexities
__setitem__
Sets the i-th element of the array
Arguments
i: int: indexx: T: new element
Complexities
prod
Calculates the product of the subarray .
Arguments
l: int: left endpoint of the range (inclusive)r: int: right endpoint of the range (exclusive)
Returns
T:
Complexities
bisect_left
Finds the largest such that product of subarray is less than .
Arguments
l: int: left endpoint of the range (inclusive)x: T: threshold
Returns
int: largest right endpoint such that (exclusive).
