


"""simple docstring"""
from __future__ import annotations

import math




class 	lowercase__				:





   def __init__(							self      ,   SCREAMING_SNAKE_CASE)  ->  None:
      _lowerCamelCase	:					List[Any]   =		size
      # approximate the overall size of segment tree with given value
      _lowerCamelCase	:					List[Any]   =		[0 for i in range(0      ,   4 * size)]
      # create array to store lazy update
      _lowerCamelCase	:					Optional[Any]   =		[0 for i in range(0      ,   4 * size)]
      _lowerCamelCase	:					Optional[int]   =		[0 for i in range(0      ,   4 * size)]  # flag for lazy update





   def 		UpperCamelCase_  (							self      ,   SCREAMING_SNAKE_CASE)  ->  int:
      return idx * 2





   def 		UpperCamelCase_  (							self      ,   SCREAMING_SNAKE_CASE)  ->  int:
      return idx * 2 + 1





   def 		UpperCamelCase_  (							self      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE)  ->  None:
      if left_element == right_element:
         _lowerCamelCase	:					int   =		a[left_element - 1]
      else:
         _lowerCamelCase	:					int   =		(left_element + right_element) // 2
         self.build(self.left(SCREAMING_SNAKE_CASE)      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE)
         self.build(self.right(SCREAMING_SNAKE_CASE)      ,   mid + 1      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE)
         _lowerCamelCase	:					Any   =		max(
             self.segment_tree[self.left(SCREAMING_SNAKE_CASE)]      ,   self.segment_tree[self.right(SCREAMING_SNAKE_CASE)])





   def 		UpperCamelCase_  (							self      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE)  ->  bool:
      if self.flag[idx] is True:
         _lowerCamelCase	:					Dict   =		self.lazy[idx]
         _lowerCamelCase	:					Tuple   =		False
         if left_element != right_element:
            _lowerCamelCase	:					Tuple   =		self.lazy[idx]
            _lowerCamelCase	:					Any   =		self.lazy[idx]
            _lowerCamelCase	:					List[Any]   =		True
            _lowerCamelCase	:					Optional[Any]   =		True

      if right_element < a or left_element > b:
         return True
      if left_element >= a and right_element <= b:
         _lowerCamelCase	:					str   =		val
         if left_element != right_element:
            _lowerCamelCase	:					Tuple   =		val
            _lowerCamelCase	:					Optional[int]   =		val
            _lowerCamelCase	:					str   =		True
            _lowerCamelCase	:					Union[str, Any]   =		True
         return True
      _lowerCamelCase	:					Dict   =		(left_element + right_element) // 2
      self.update(self.left(SCREAMING_SNAKE_CASE)      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE)
      self.update(self.right(SCREAMING_SNAKE_CASE)      ,   mid + 1      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE)
      _lowerCamelCase	:					Union[str, Any]   =		max(
          self.segment_tree[self.left(SCREAMING_SNAKE_CASE)]      ,   self.segment_tree[self.right(SCREAMING_SNAKE_CASE)])
      return True





   def 		UpperCamelCase_  (							self      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE)  ->  int | float:
      if self.flag[idx] is True:
         _lowerCamelCase	:					Optional[Any]   =		self.lazy[idx]
         _lowerCamelCase	:					Optional[Any]   =		False
         if left_element != right_element:
            _lowerCamelCase	:					List[Any]   =		self.lazy[idx]
            _lowerCamelCase	:					Dict   =		self.lazy[idx]
            _lowerCamelCase	:					List[str]   =		True
            _lowerCamelCase	:					Optional[Any]   =		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]
      _lowerCamelCase	:					List[str]   =		(left_element + right_element) // 2
      _lowerCamelCase	:					Optional[int]   =		self.query(self.left(SCREAMING_SNAKE_CASE)      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE)
      _lowerCamelCase	:					Any   =		self.query(self.right(SCREAMING_SNAKE_CASE)      ,   mid + 1      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE)
      return max(SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE)





   def __str__(							self)  ->  str:
      return str([self.query(1      ,   1      ,   self.size      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE) for i in range(1      ,   self.size + 1)])


if __name__ == "__main__":
 UpperCAmelCase				=						[1, 2, -4, 7, 3, -5, 6, 11, -20, 9, 14, 15, 5, 2, -8]
 UpperCAmelCase				=						15
 UpperCAmelCase				=						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)









"""simple docstring"""


import numpy as np
from cva import destroyAllWindows, imread, imshow, waitKey




class 						__UpperCamelCase     :
					def __init__(							self							:	Union[str, Any]     , UpperCAmelCase							:	Union[str, Any]     , UpperCAmelCase							:	int     , UpperCAmelCase							:	int   )	->       Tuple:
											if dst_width < 0 or dst_height < 0:
																	raise ValueError('Destination width/height should be > 0'   )

											lowerCAmelCase   :List[Any]						=			img
											lowerCAmelCase   :Optional[int]						=			img.shape[1]
											lowerCAmelCase   :Union[str, Any]						=			img.shape[0]
											lowerCAmelCase   :Optional[int]						=			dst_width
											lowerCAmelCase   :Optional[int]						=			dst_height

											lowerCAmelCase   :Any						=			self.src_w / self.dst_w
											lowerCAmelCase   :Dict						=			self.src_h / self.dst_h

											lowerCAmelCase   :int						=			(
											    np.ones((self.dst_h, self.dst_w, 3)     , np.uinta   ) * 255
											)
					def        UpperCAmelCase__ (							self							:	Union[str, Any]   )	->       List[str]:
											for i in range(self.dst_h   ):
																	for j in range(self.dst_w   ):
																							lowerCAmelCase   :Optional[Any]						=			self.img[self.get_y(UpperCAmelCase   )][self.get_x(UpperCAmelCase   )]
					def        UpperCAmelCase__ (							self							:	Optional[int]     , UpperCAmelCase							:	int   )	->       int:
											return int(self.ratio_x * x   )
					def        UpperCAmelCase__ (							self							:	List[str]     , UpperCAmelCase							:	int   )	->       int:
											return int(self.ratio_y * y   )


if __name__ == "__main__":
		__SCREAMING_SNAKE_CASE,						__SCREAMING_SNAKE_CASE   =   8_00, 6_00
		__SCREAMING_SNAKE_CASE   =   imread('image_data/lena.jpg', 1)
		__SCREAMING_SNAKE_CASE   =   NearestNeighbour(im, dst_w, dst_h)
		n.process()

		imshow(
		    F"""Image resized from: {im.shape[1]}x{im.shape[0]} to {dst_w}x{dst_h}""", n.output
		)
		waitKey(0)
		destroyAllWindows()