





import math







class 						_lowerCAmelCase:

  """simple docstring"""







  def __init__( self  ,    UpperCAmelCase     )-> Tuple:
     __A				 =       len(UpperCAmelCase     )
     __A				 =       [0] * (
         4 * self.N
     )  # approximate the overall size of segment tree with array N
     self.build(1  ,    0  ,    self.N - 1     )

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase     )-> Optional[int]:
     return idx * 2

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase     )-> Optional[int]:
     return idx * 2 + 1

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase     )-> Optional[Any]:  # noqa: E741
     if l == r:
        __A				 =       A[l]
     else:
        __A				 =       (l + r) // 2
        self.build(self.left(UpperCAmelCase     )  ,    UpperCAmelCase  ,    UpperCAmelCase     )
        self.build(self.right(UpperCAmelCase     )  ,    mid + 1  ,    UpperCAmelCase     )
        __A				 =       max(self.st[self.left(UpperCAmelCase     )]  ,    self.st[self.right(UpperCAmelCase     )]     )

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase     )-> List[Any]:
     return self.update_recursive(1  ,    0  ,    self.N - 1  ,    a - 1  ,    b - 1  ,    UpperCAmelCase     )

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase     )-> str:  # noqa: E741
     if r < a or l > b:
        return True
     if l == r:
        __A				 =       val
        return True
     __A				 =       (l + r) // 2
     self.update_recursive(self.left(UpperCAmelCase     )  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase     )
     self.update_recursive(self.right(UpperCAmelCase     )  ,    mid + 1  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase     )
     __A				 =       max(self.st[self.left(UpperCAmelCase     )]  ,    self.st[self.right(UpperCAmelCase     )]     )
     return True

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase  ,    UpperCAmelCase     )-> List[Any]:
     return self.query_recursive(1  ,    0  ,    self.N - 1  ,    a - 1  ,    b - 1     )

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase     )-> Optional[int]:  # noqa: E741
     if r < a or l > b:
        return -math.inf
     if l >= a and r <= b:
        return self.st[idx]
     __A				 =       (l + r) // 2
     __A				 =       self.query_recursive(self.left(UpperCAmelCase     )  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase     )
     __A				 =       self.query_recursive(self.right(UpperCAmelCase     )  ,    mid + 1  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase     )
     return max(UpperCAmelCase  ,    UpperCAmelCase     )





  def 		SCREAMING_SNAKE_CASE__	( self     )-> List[str]:
     __A				 =       []
     for i in range(1  ,    N + 1     ):
        show_list += [self.query(UpperCAmelCase  ,    UpperCAmelCase     )]
     print(UpperCAmelCase     )


if __name__ == "__main__":
    _UpperCamelCase   :							List[Any]     =	[1, 2, -4, 7, 3, -5, 6, 1_1, -2_0, 9, 1_4, 1_5, 5, 2, -8]
    _UpperCamelCase   :							Optional[int]     =	1_5
    _UpperCamelCase   :							Optional[int]     =	SegmentTree(A)
    print(segt.query(4, 6))
    print(segt.query(7, 1_1))
    print(segt.query(7, 1_2))
    segt.update(1, 3, 1_1_1)
    print(segt.query(1, 1_5))
    segt.update(7, 8, 2_3_5)
    segt.show_data()








import numpy as np
def 				__UpperCamelCase  (		snake_case     )  ->						Any:


   '''simple docstring'''







   __A ,						__A				 =       a.shape
   __A				 =       min(snake_case    ,	snake_case     )
   __A				 =       np.eye(snake_case     )
   __A				 =       a.copy()

   for k in range(t - 1     ):
      # select a column of modified matrix A':
      __A				 =       r[k:, [k]]
      # construct first basis vector
      __A				 =       np.zeros_like(snake_case     )
      __A				 =       1.0
      # determine scaling factor
      __A				 =       np.linalg.norm(snake_case     )
      # construct vector v for Householder reflection
      __A				 =       x + np.sign(x[0]     ) * alpha * ea
      v /= np.linalg.norm(snake_case     )

      # construct the Householder matrix
      __A				 =       np.eye(m - k     ) - 2.0 * v @ v.T
      # pad with ones and zeros as necessary
      __A				 =       np.block([[np.eye(snake_case     ), np.zeros((k, m - k)     )], [np.zeros((m - k, k)     ), q_k]]     )

      __A				 =       q @ q_k.T
      __A				 =       q_k @ r

   return q, r


if __name__ == "__main__":
    import doctest

    doctest.testmod()

