Source code for titan_pylib.data_structures.segment_tree.segment_tree_interface
1from abc import ABC, abstractmethod
2from typing import TypeVar, Generic, Union, Iterable, Callable
3
4T = TypeVar("T")
5
6
[docs]
7class SegmentTreeInterface(ABC, Generic[T]):
8
9 @abstractmethod
10 def __init__(self, n_or_a: Union[int, Iterable[T]], op: Callable[[T, T], T], e: T):
11 raise NotImplementedError
12
[docs]
13 @abstractmethod
14 def set(self, k: int, v: T) -> None:
15 raise NotImplementedError
16
[docs]
17 @abstractmethod
18 def get(self, k: int) -> T:
19 raise NotImplementedError
20
[docs]
21 @abstractmethod
22 def prod(self, l: int, r: int) -> T:
23 raise NotImplementedError
24
[docs]
25 @abstractmethod
26 def all_prod(self) -> T:
27 raise NotImplementedError
28
[docs]
29 @abstractmethod
30 def max_right(self, l: int, f: Callable[[T], bool]) -> int:
31 raise NotImplementedError
32
[docs]
33 @abstractmethod
34 def min_left(self, r: int, f: Callable[[T], bool]) -> int:
35 raise NotImplementedError
36
[docs]
37 @abstractmethod
38 def tolist(self) -> list[T]:
39 raise NotImplementedError
40
41 @abstractmethod
42 def __getitem__(self, k: int) -> T:
43 raise NotImplementedError
44
45 @abstractmethod
46 def __setitem__(self, k: int, v: T) -> None:
47 raise NotImplementedError
48
49 @abstractmethod
50 def __str__(self):
51 raise NotImplementedError
52
53 @abstractmethod
54 def __repr__(self):
55 raise NotImplementedError