


from collections.abc import Sequence
from queue import Queue




class 			UpperCamelCase_     :

	"""simple docstring"""





	def __init__(			self      :    Dict      ,      UpperCAmelCase__      :    List[Any]      ,      UpperCAmelCase__      :    Union[str, Any]      ,      UpperCAmelCase__      :    str      ,      UpperCAmelCase__      :    Union[str, Any]=None      ,      UpperCAmelCase__      :    Optional[int]=None       )	->     List[str]:
						__SCREAMING_SNAKE_CASE						       =    start
						__SCREAMING_SNAKE_CASE						       =    end
						__SCREAMING_SNAKE_CASE						       =    val
						__SCREAMING_SNAKE_CASE						       =    (start + end) // 2
						__SCREAMING_SNAKE_CASE						       =    left
						__SCREAMING_SNAKE_CASE						       =    right




	def __repr__(			self      :    int       )	->     int:
						return F"""SegmentTreeNode(start={self.start}, end={self.end}, val={self.val})"""




class 			UpperCamelCase_     :

	"""simple docstring"""





	def __init__(			self      :    Dict      ,      UpperCAmelCase__      :    Optional[Any]      ,      UpperCAmelCase__      :    Tuple       )	->     Tuple:
						__SCREAMING_SNAKE_CASE						       =    collection
						__SCREAMING_SNAKE_CASE						       =    function
						if self.collection:
											__SCREAMING_SNAKE_CASE						       =    self._build_tree(0      ,      len(UpperCAmelCase__       ) - 1       )




	def   UpperCAmelCase_				(			self      :    str      ,      UpperCAmelCase__      :    Union[str, Any]      ,      UpperCAmelCase__      :    str       )	->     List[str]:
						self._update_tree(self.root      ,      UpperCAmelCase__      ,      UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    List[str]      ,      UpperCAmelCase__      :    Optional[Any]      ,      UpperCAmelCase__      :    Optional[Any]       )	->     Tuple:
						return self._query_range(self.root      ,      UpperCAmelCase__      ,      UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    Tuple      ,      UpperCAmelCase__      :    Dict      ,      UpperCAmelCase__      :    Optional[int]       )	->     List[str]:

						if start == end:
											return SegmentTreeNode(UpperCAmelCase__      ,      UpperCAmelCase__      ,      self.collection[start]       )
						__SCREAMING_SNAKE_CASE						       =    (start + end) // 2
						__SCREAMING_SNAKE_CASE						       =    self._build_tree(UpperCAmelCase__      ,      UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    self._build_tree(mid + 1      ,      UpperCAmelCase__       )
						return SegmentTreeNode(UpperCAmelCase__      ,      UpperCAmelCase__      ,      self.fn(left.val      ,      right.val       )      ,      UpperCAmelCase__      ,      UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    Optional[int]      ,      UpperCAmelCase__      :    Tuple      ,      UpperCAmelCase__      :    int      ,      UpperCAmelCase__      :    Union[str, Any]       )	->     int:

						if node.start == i and node.end == i:
											__SCREAMING_SNAKE_CASE						       =    val
											return
						if i <= node.mid:
											self._update_tree(node.left      ,      UpperCAmelCase__      ,      UpperCAmelCase__       )
						else:
											self._update_tree(node.right      ,      UpperCAmelCase__      ,      UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    self.fn(node.left.val      ,      node.right.val       )




	def   UpperCAmelCase_				(			self      :    Optional[int]      ,      UpperCAmelCase__      :    Dict      ,      UpperCAmelCase__      :    Optional[int]      ,      UpperCAmelCase__      :    str       )	->     List[str]:

						if node.start == i and node.end == j:
											return node.val

						if i <= node.mid:
											if j <= node.mid:
																# range in left child tree
																return self._query_range(node.left      ,      UpperCAmelCase__      ,      UpperCAmelCase__       )
											else:
																# range in left child tree and right child tree
																return self.fn(
																    self._query_range(node.left      ,      UpperCAmelCase__      ,      node.mid       )      ,      self._query_range(node.right      ,      node.mid + 1      ,      UpperCAmelCase__       )      ,      )
						else:
											# range in right child tree
											return self._query_range(node.right      ,      UpperCAmelCase__      ,      UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    Tuple       )	->     Optional[int]:

						if self.root is not None:
											__SCREAMING_SNAKE_CASE						       =    Queue()
											queue.put(self.root       )
											while not queue.empty():
																__SCREAMING_SNAKE_CASE						       =    queue.get()
																yield node

																if node.left is not None:
																					queue.put(node.left       )

																if node.right is not None:
																					queue.put(node.right       )


if __name__ == "__main__":
		import operator

		for fn in [operator.add, max, min]:
				print('''*''' * 5_0)
				a__    :							str            =					SegmentTree([2, 1, 5, 3, 4], fn)
				for node in arr.traverse():
						print(node)
				print()

				arr.update(1, 5)
				for node in arr.traverse():
						print(node)
				print()

				print(arr.query_range(3, 4))  # 7
				print(arr.query_range(2, 2))  # 5
				print(arr.query_range(1, 3))  # 13
				print()




"""simple docstring"""







def        UpperCAmelCase__	(lowerCAmelCase_  ,						lowerCAmelCase_       ):




					'''simple docstring'''


					if digit_amount > 0:
										return round(number - int(lowerCAmelCase_       )  ,						lowerCAmelCase_       )
					return number - int(lowerCAmelCase_       )


if __name__ == "__main__":
		print(decimal_isolate(1.53, 0))
		print(decimal_isolate(35.3_45, 1))
		print(decimal_isolate(35.3_45, 2))
		print(decimal_isolate(35.3_45, 3))
		print(decimal_isolate(-14.7_89, 3))
		print(decimal_isolate(0, 2))
		print(decimal_isolate(-14.1_23, 1))
		print(decimal_isolate(-14.1_23, 2))
		print(decimal_isolate(-14.1_23, 3))
