





from __future__ import annotations

import math

class  __A:

     def __init__(      self,       A      ):





            """simple docstring"""

            _UpperCamelCase              =						size
            # approximate the overall size of segment tree with given value
            _UpperCamelCase              =						[0 for i in range(0,       4 * size      )]
            # create array to store lazy update
            _UpperCamelCase              =						[0 for i in range(0,       4 * size      )]
            _UpperCamelCase              =						[0 for i in range(0,       4 * size      )]  # flag for lazy update

     def 	_UpperCamelCase     (      self,       A      ):





            """simple docstring"""

            return idx * 2

     def 	_UpperCamelCase     (      self,       A      ):





            """simple docstring"""

            return idx * 2 + 1

     def 	_UpperCamelCase     (      self,       A,       A,       A,       A      ):





            """simple docstring"""

            if left_element == right_element:
                   _UpperCamelCase              =						a[left_element - 1]
            else:
                   _UpperCamelCase              =						(left_element + right_element) // 2
                   self.build(self.left(A      ),       A,       A,       A      )
                   self.build(self.right(A      ),       mid + 1,       A,       A      )
                   _UpperCamelCase              =						max(
                       self.segment_tree[self.left(A      )],       self.segment_tree[self.right(A      )]      )

     def 	_UpperCamelCase     (      self,       A,       A,       A,       A,       A,       A      ):





            """simple docstring"""

            if self.flag[idx] is True:
                   _UpperCamelCase              =						self.lazy[idx]
                   _UpperCamelCase              =						False
                   if left_element != right_element:
                          _UpperCamelCase              =						self.lazy[idx]
                          _UpperCamelCase              =						self.lazy[idx]
                          _UpperCamelCase              =						True
                          _UpperCamelCase              =						True

            if right_element < a or left_element > b:
                   return True
            if left_element >= a and right_element <= b:
                   _UpperCamelCase              =						val
                   if left_element != right_element:
                          _UpperCamelCase              =						val
                          _UpperCamelCase              =						val
                          _UpperCamelCase              =						True
                          _UpperCamelCase              =						True
                   return True
            _UpperCamelCase              =						(left_element + right_element) // 2
            self.update(self.left(A      ),       A,       A,       A,       A,       A      )
            self.update(self.right(A      ),       mid + 1,       A,       A,       A,       A      )
            _UpperCamelCase              =						max(
                self.segment_tree[self.left(A      )],       self.segment_tree[self.right(A      )]      )
            return True

     def 	_UpperCamelCase     (      self,       A,       A,       A,       A,       A      ):





            """simple docstring"""

            if self.flag[idx] is True:
                   _UpperCamelCase              =						self.lazy[idx]
                   _UpperCamelCase              =						False
                   if left_element != right_element:
                          _UpperCamelCase              =						self.lazy[idx]
                          _UpperCamelCase              =						self.lazy[idx]
                          _UpperCamelCase              =						True
                          _UpperCamelCase              =						True
            if right_element < a or left_element > b:
                   return -math.inf
            if left_element >= a and right_element <= b:
                   return self.segment_tree[idx]
            _UpperCamelCase              =						(left_element + right_element) // 2
            _UpperCamelCase              =						self.query(self.left(A      ),       A,       A,       A,       A      )
            _UpperCamelCase              =						self.query(self.right(A      ),       mid + 1,       A,       A,       A      )
            return max(A,       A      )



     def __str__(      self      ):





            """simple docstring"""

            return str([self.query(1,       1,       self.size,       A,       A      ) for i in range(1,       self.size + 1      )]      )


if __name__ == "__main__":
   lowercase    : str    	=  [1, 2, -4, 7, 3, -5, 6, 11, -20, 9, 14, 15, 5, 2, -8]
   lowercase    : str    	=  15
   lowercase    : Union[str, Any]    	=  SegmentTree(size)
   segt.build(1, 1, size, A)
   print(segt.query(1, 1, size, 4, 6))
   print(segt.query(1, 1, size, 7, 11))
   print(segt.query(1, 1, size, 7, 12))
   segt.update(1, 1, size, 1, 3, 111)
   print(segt.query(1, 1, size, 1, 15))
   segt.update(1, 1, size, 7, 8, 235)
   print(segt)













from __future__ import annotations

import math

import numpy as np
from numpy.linalg import norm


def     SCREAMING_SNAKE_CASE			(      lowerCAmelCase    ,       lowerCAmelCase					):
       return math.sqrt(sum(pow(a - b    ,       2					) for a, b in zip(lowerCAmelCase    ,       lowerCAmelCase					)					)					)


def     SCREAMING_SNAKE_CASE			(      lowerCAmelCase    ,       lowerCAmelCase					):

       if dataset.ndim != value_array.ndim:
              _UpperCamelCase              =						(
                  '''Wrong input data\'s dimensions... '''
                  f'''dataset : {dataset.ndim}, value_array : {value_array.ndim}'''
              )
              raise ValueError(lowerCAmelCase					)

       try:
              if dataset.shape[1] != value_array.shape[1]:
                     _UpperCamelCase              =						(
                         '''Wrong input data\'s shape... '''
                         f'''dataset : {dataset.shape[1]}, value_array : {value_array.shape[1]}'''
                     )
                     raise ValueError(lowerCAmelCase					)
       except IndexError:
              if dataset.ndim != value_array.ndim:
                     raise TypeError('''Wrong shape'''					)

       if dataset.dtype != value_array.dtype:
              _UpperCamelCase              =						(
                  '''Input data have different datatype... '''
                  f'''dataset : {dataset.dtype}, value_array : {value_array.dtype}'''
              )
              raise TypeError(lowerCAmelCase					)

       _UpperCamelCase              =						[]

       for value in value_array:
              _UpperCamelCase              =						euclidean(lowerCAmelCase    ,       dataset[0]					)
              _UpperCamelCase              =						dataset[0].tolist()

              for dataset_value in dataset[1:]:
                     _UpperCamelCase              =						euclidean(lowerCAmelCase    ,       lowerCAmelCase					)

                     if dist > temp_dist:
                            _UpperCamelCase              =						temp_dist
                            _UpperCamelCase              =						dataset_value.tolist()

              answer.append([vector, dist]					)

       return answer


def     SCREAMING_SNAKE_CASE			(      lowerCAmelCase    ,       lowerCAmelCase					):
       return np.dot(lowerCAmelCase    ,       lowerCAmelCase					) / (norm(lowerCAmelCase					) * norm(lowerCAmelCase					))


if __name__ == "__main__":
       import doctest

       doctest.testmod()






