

'''simple docstring'''




from collections.abc import Sequence
from queue import Queue



class 							lowercase_						:

  '''simple docstring'''





  def __init__(  self ,			a_ ,			a_ ,			a_ ,			a_=None ,			a_=None  )				->					Dict:


    """simple docstring"""
    UpperCAmelCase    				=						start
    UpperCAmelCase    				=						end
    UpperCAmelCase    				=						val
    UpperCAmelCase    				=						(start + end) // 2
    UpperCAmelCase    				=						left
    UpperCAmelCase    				=						right





  def __repr__(  self  )				->					Dict:


    """simple docstring"""
    return F'''SegmentTreeNode(start={self.start}, end={self.end}, val={self.val})'''




class 							lowercase_						:

  '''simple docstring'''





  def __init__(  self ,			a_ ,			a_  )				->					Dict:


    """simple docstring"""
    UpperCAmelCase    				=						collection
    UpperCAmelCase    				=						function
    if self.collection:
      UpperCAmelCase    				=						self._build_tree(0 ,			len(a_  ) - 1  )
  def     snake_case_      (  self ,			a_ ,			a_  )				->					Tuple:


    """simple docstring"""
    self._update_tree(self.root ,			a_ ,			a_  )
  def     snake_case_      (  self ,			a_ ,			a_  )				->					Tuple:


    """simple docstring"""
    return self._query_range(self.root ,			a_ ,			a_  )
  def     snake_case_      (  self ,			a_ ,			a_  )				->					Dict:


    """simple docstring"""
    if start == end:
      return SegmentTreeNode(a_ ,			a_ ,			self.collection[start]  )
    UpperCAmelCase    				=						(start + end) // 2
    UpperCAmelCase    				=						self._build_tree(a_ ,			a_  )
    UpperCAmelCase    				=						self._build_tree(mid + 1 ,			a_  )
    return SegmentTreeNode(a_ ,			a_ ,			self.fn(left.val ,			right.val  ) ,			a_ ,			a_  )
  def     snake_case_      (  self ,			a_ ,			a_ ,			a_  )				->					Optional[Any]:


    """simple docstring"""
    if node.start == i and node.end == i:
      UpperCAmelCase    				=						val
      return
    if i <= node.mid:
      self._update_tree(node.left ,			a_ ,			a_  )
    else:
      self._update_tree(node.right ,			a_ ,			a_  )
    UpperCAmelCase    				=						self.fn(node.left.val ,			node.right.val  )
  def     snake_case_      (  self ,			a_ ,			a_ ,			a_  )				->					Tuple:


    """simple docstring"""
    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 ,			a_ ,			a_  )
      else:
        # range in left child tree and right child tree
        return self.fn(
            self._query_range(node.left ,			a_ ,			node.mid  ) ,			self._query_range(node.right ,			node.mid + 1 ,			a_  ) ,			)
    else:
      # range in right child tree
      return self._query_range(node.right ,			a_ ,			a_  )





  def     snake_case_      (  self  )				->					List[str]:


    """simple docstring"""
    if self.root is not None:
      UpperCAmelCase    				=						Queue()
      queue.put(self.root  )
      while not queue.empty():
        UpperCAmelCase    				=						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('*' * 50)
    _a					:			Optional[Any]							=    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    lowerCamelCase__		(    SCREAMING_SNAKE_CASE   : List[Any]							, SCREAMING_SNAKE_CASE   : Union[str, Any]    ):
  # "extended trapezoidal rule"
  # int(f) = dx/2 * (f1 + 2f2 + ... + fn)
  UpperCAmelCase    				=						(boundary[1] - boundary[0]) / steps
  UpperCAmelCase    				=						boundary[0]
  UpperCAmelCase    				=						boundary[1]
  UpperCAmelCase    				=						make_points(SCREAMING_SNAKE_CASE							, SCREAMING_SNAKE_CASE							, SCREAMING_SNAKE_CASE    )
  UpperCAmelCase    				=						0.0
  y += (h / 2.0) * f(SCREAMING_SNAKE_CASE    )
  for i in x_i:
    # print(i)
    y += h * f(SCREAMING_SNAKE_CASE    )
  y += (h / 2.0) * f(SCREAMING_SNAKE_CASE    )
  return y


def    lowerCamelCase__		(    SCREAMING_SNAKE_CASE   : Tuple							, SCREAMING_SNAKE_CASE   : Dict							, SCREAMING_SNAKE_CASE   : Tuple    ):
  UpperCAmelCase    				=						a + h
  while x < (b - h):
    yield x
    UpperCAmelCase    				=						x + h


def    lowerCamelCase__		(    SCREAMING_SNAKE_CASE   : Optional[Any]    ):  # enter your function here
  UpperCAmelCase    				=						(x - 0) * (x - 0)
  return y


def    lowerCamelCase__		(    ):
  UpperCAmelCase    				=						0.0  # Lower bound of integration
  UpperCAmelCase    				=						1.0  # Upper bound of integration
  UpperCAmelCase    				=						10.0  # define number of steps or resolution
  UpperCAmelCase    				=						[a, b]  # define boundary of integration
  UpperCAmelCase    				=						method_a(SCREAMING_SNAKE_CASE							, SCREAMING_SNAKE_CASE    )
  print(f'''y = {y}'''    )


if __name__ == "__main__":
  main()


