import warnings
from collections.abc import Callable
from typing import Any

import numpy
from matplotlib import pyplot

lowerCAmelCase__	:  Any						=  0.25 + 0.0j
lowerCAmelCase__	:  int						=  -0.4 + 0.6j
lowerCAmelCase__	:  str						=  -0.1 + 0.651j
lowerCAmelCase__	:  Dict						=  -2.0
lowerCAmelCase__	:  Dict						=  56
lowerCAmelCase__	:  Tuple						=  2.0
lowerCAmelCase__	:  Dict						=  6_66
def 					UpperCamelCase__		(							A__     ,					A__       )  ->   numpy.ndarray:
				return numpy.exp(A__       ) + c_parameter
def 					UpperCamelCase__		(							A__     ,					A__       )  ->   numpy.ndarray:
				return z_values * z_values + c_parameter
def 					UpperCamelCase__		(							A__     ,					A__       )  ->   numpy.ndarray:
				snake_case__   :      Dict   				= numpy.linspace(-window_size     ,					A__     ,					A__       )
				snake_case__   :      str   				= x.reshape((nb_pixels, 1)       )
				snake_case__   :      int   				= numpy.linspace(-window_size     ,					A__     ,					A__       )
				snake_case__   :      Optional[Any]   				= y.reshape((1, nb_pixels)       )
				return x + 1.0j * y
def 					UpperCamelCase__		(							A__     ,					A__     ,					A__     ,					A__     ,					A__ = None     ,					)  ->   numpy.ndarray:
				snake_case__   :      Optional[Any]   				= z_a.astype('complex64'       )
				for _ in range(A__       ):
								snake_case__   :      List[str]   				= eval_function(A__     ,					A__       )
								if infinity is not None:
												numpy.nan_to_num(A__     ,					copy=A__     ,					nan=A__       )
												snake_case__   :      Union[str, Any]   				= infinity
				return z_n
def 					UpperCamelCase__		(							A__     ,					A__     ,					A__     ,					A__     ,					)  ->   None:
				snake_case__   :      List[Any]   				= (abs(A__       )).transpose()
				snake_case__   :      Any   				= abs_z_final[::-1, :]
				pyplot.matshow(abs_z_final < escape_radius       )
				pyplot.title(F"""Julia set of ${function_label}$, $c={function_params}$"""       )
				pyplot.show()
def 					UpperCamelCase__		(							)  ->   None:
				warnings.filterwarnings(
				    'ignore'     ,					category=A__     ,					message='overflow encountered in multiply'       )
				warnings.filterwarnings(
				    'ignore'     ,					category=A__     ,					message='invalid value encountered in multiply'     ,					)
				warnings.filterwarnings(
				    'ignore'     ,					category=A__     ,					message='overflow encountered in absolute'       )
				warnings.filterwarnings(
				    'ignore'     ,					category=A__     ,					message='overflow encountered in exp'       )


if __name__ == "__main__":
				lowerCAmelCase__	:  Optional[int]						=  prepare_grid(window_size, nb_pixels)

				ignore_overflow_warnings()  # See file header for explanations

				lowerCAmelCase__	:  Optional[int]						=  24
				lowerCAmelCase__	:  Optional[Any]						=  2 * abs(c_cauliflower) + 1
				lowerCAmelCase__	:  str						=  iterate_function(
				    eval_quadratic_polynomial,
				    c_cauliflower,
				    nb_iterations,
				    z_a,
				    infinity=1.1 * escape_radius,
				)
				show_results('''z^2+c''', c_cauliflower, escape_radius, z_final)

				lowerCAmelCase__	:  int						=  64
				lowerCAmelCase__	:  Optional[int]						=  2 * abs(c_polynomial_a) + 1
				lowerCAmelCase__	:  Optional[int]						=  iterate_function(
				    eval_quadratic_polynomial,
				    c_polynomial_a,
				    nb_iterations,
				    z_a,
				    infinity=1.1 * escape_radius,
				)
				show_results('''z^2+c''', c_polynomial_a, escape_radius, z_final)

				lowerCAmelCase__	:  Any						=  1_61
				lowerCAmelCase__	:  int						=  2 * abs(c_polynomial_a) + 1
				lowerCAmelCase__	:  Union[str, Any]						=  iterate_function(
				    eval_quadratic_polynomial,
				    c_polynomial_a,
				    nb_iterations,
				    z_a,
				    infinity=1.1 * escape_radius,
				)
				show_results('''z^2+c''', c_polynomial_a, escape_radius, z_final)

				lowerCAmelCase__	:  int						=  12
				lowerCAmelCase__	:  Tuple						=  1_00_00.0
				lowerCAmelCase__	:  Union[str, Any]						=  iterate_function(
				    eval_exponential,
				    c_exponential,
				    nb_iterations,
				    z_a + 2,
				    infinity=1.0E10,
				)
				show_results('''e^z+c''', c_exponential, escape_radius, z_final)



import math





class 					__snake_case    :




					def __init__(  self       ,			__UpperCamelCase						)	->    Dict:



									'''simple docstring'''







									snake_case__   :      Optional[int]   				= len(__UpperCamelCase						)
									snake_case__   :      Dict   				= [0] * (
									    4 * self.N
									)  # approximate the overall size of segment tree with array N
									self.build(1       ,			0       ,			self.N - 1						)




					def      __a     (  self       ,			__UpperCamelCase						)	->    Any:



									'''simple docstring'''







									return idx * 2




					def      __a     (  self       ,			__UpperCamelCase						)	->    Optional[int]:



									'''simple docstring'''







									return idx * 2 + 1




					def      __a     (  self       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase						)	->    int:  # noqa: E741



									'''simple docstring'''







									if l == r:
													snake_case__   :      Dict   				= A[l]
									else:
													snake_case__   :      Optional[Any]   				= (l + r) // 2
													self.build(self.left(__UpperCamelCase						)       ,			__UpperCamelCase       ,			__UpperCamelCase						)
													self.build(self.right(__UpperCamelCase						)       ,			mid + 1       ,			__UpperCamelCase						)
													snake_case__   :      int   				= max(self.st[self.left(__UpperCamelCase						)]       ,			self.st[self.right(__UpperCamelCase						)]						)




					def      __a     (  self       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase						)	->    int:



									'''simple docstring'''







									return self.update_recursive(1       ,			0       ,			self.N - 1       ,			a - 1       ,			b - 1       ,			__UpperCamelCase						)




					def      __a     (  self       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase						)	->    Tuple:  # noqa: E741



									'''simple docstring'''







									if r < a or l > b:
													return True
									if l == r:
													snake_case__   :      List[str]   				= val
													return True
									snake_case__   :      str   				= (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						)
									snake_case__   :      Tuple   				= max(self.st[self.left(__UpperCamelCase						)]       ,			self.st[self.right(__UpperCamelCase						)]						)
									return True




					def      __a     (  self       ,			__UpperCamelCase       ,			__UpperCamelCase						)	->    List[str]:



									'''simple docstring'''







									return self.query_recursive(1       ,			0       ,			self.N - 1       ,			a - 1       ,			b - 1						)




					def      __a     (  self       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase						)	->    Optional[int]:  # noqa: E741



									'''simple docstring'''







									if r < a or l > b:
													return -math.inf
									if l >= a and r <= b:
													return self.st[idx]
									snake_case__   :      str   				= (l + r) // 2
									snake_case__   :      Optional[Any]   				= self.query_recursive(self.left(__UpperCamelCase						)       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase						)
									snake_case__   :      List[str]   				= self.query_recursive(self.right(__UpperCamelCase						)       ,			mid + 1       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase						)
									return max(__UpperCamelCase       ,			__UpperCamelCase						)




					def      __a     (  self						)	->    Optional[Any]:



									'''simple docstring'''







									snake_case__   :      Tuple   				= []
									for i in range(1       ,			N + 1						):
													show_list += [self.query(__UpperCamelCase       ,			__UpperCamelCase						)]
									print(__UpperCamelCase						)


if __name__ == "__main__":
				lowerCAmelCase__	:  Optional[int]						=  [1, 2, -4, 7, 3, -5, 6, 11, -20, 9, 14, 15, 5, 2, -8]
				lowerCAmelCase__	:  Any						=  15
				lowerCAmelCase__	:  List[Any]						=  SegmentTree(A)
				print(segt.query(4, 6))
				print(segt.query(7, 11))
				print(segt.query(7, 12))
				segt.update(1, 3, 1_11)
				print(segt.query(1, 15))
				segt.update(7, 8, 2_35)
				segt.show_data()


