





'''simple docstring'''






from __future__ import annotations

from collections.abc import Callable
from typing import Any, Generic, TypeVar

lowerCAmelCase       		=      TypeVar("""T""")
class 		lowerCamelCase  (      Generic[T]       ):



	def __init__(   self		,      a_		,      a_	):
			lowerCAmelCase     :    Any | T						=   None

			lowerCAmelCase     :    int						=   len(a_	)
			lowerCAmelCase     :    list[T]						=   [any_type for _ in range(self.N	)] + arr
			lowerCAmelCase     :    Dict						=   fnc
			self.build()



	def   _lowerCamelCase    (   self	):
			for p in range(self.N - 1		,      0		,      -1	):
					lowerCAmelCase     :    Dict						=   self.fn(self.st[p * 2]		,      self.st[p * 2 + 1]	)



	def   _lowerCamelCase    (   self		,      a_		,      a_	):
			p += self.N
			lowerCAmelCase     :    str						=   v
			while p > 1:
					lowerCAmelCase     :    Dict						=   p // 2
					lowerCAmelCase     :    Union[str, Any]						=   self.fn(self.st[p * 2]		,      self.st[p * 2 + 1]	)





	def   _lowerCamelCase    (   self		,      a_		,      a_	):  # noqa: E741
			lowerCAmelCase	,		lowerCAmelCase     :    Dict						=   l + self.N, r + self.N

			lowerCAmelCase     :    T | None						=   None
			while l <= r:
					if l % 2 == 1:
							lowerCAmelCase     :    Dict						=   self.st[l] if res is None else self.fn(a_		,      self.st[l]	)
					if r % 2 == 0:
							lowerCAmelCase     :    str						=   self.st[r] if res is None else self.fn(a_		,      self.st[r]	)
					lowerCAmelCase	,		lowerCAmelCase     :    Any						=   (l + 1) // 2, (r - 1) // 2
			return res


if __name__ == "__main__":
					from functools import reduce

					lowerCAmelCase       		=      [1, 10, -2, 9, -3, 8, 4, -7, 5, 6, 11, -12]

					lowerCAmelCase       		=      {
					    0: 7,
					    1: 2,
					    2: 6,
					    3: -14,
					    4: 5,
					    5: 4,
					    6: 7,
					    7: -10,
					    8: 9,
					    9: 10,
					    10: 12,
					    11: 1,
					}

					lowerCAmelCase       		=      SegmentTree(test_array, min)
					lowerCAmelCase       		=      SegmentTree(test_array, max)
					lowerCAmelCase       		=      SegmentTree(test_array, lambda a, b: a + b)






					def      __A						(							):
							for i in range(len(a_	)	):
									for j in range(a_      ,len(a_	)	):
											lowerCAmelCase     :    Tuple						=   reduce(a_      ,test_array[i : j + 1]	)
											lowerCAmelCase     :    str						=   reduce(a_      ,test_array[i : j + 1]	)
											lowerCAmelCase     :    Tuple						=   reduce(lambda a_      ,a_	: a + b      ,test_array[i : j + 1]	)
											assert min_range == min_segment_tree.query(a_      ,a_	)
											assert max_range == max_segment_tree.query(a_      ,a_	)
											assert sum_range == sum_segment_tree.query(a_      ,a_	)

					test_all_segments()

					for index, value in test_updates.items():
										lowerCAmelCase       		=      value
										min_segment_tree.update(index, value)
										max_segment_tree.update(index, value)
										sum_segment_tree.update(index, value)
										test_all_segments()










'''simple docstring'''






import numpy as np






def      __A						(							a_						:  np.array	):
		return (2 / (1 + np.exp(-2 * vector	))) - 1


if __name__ == "__main__":
					import doctest

					doctest.testmod()



