"""simple docstring"""




from __future__ import annotations

import math
class     UpperCamelCase__:





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





						def 				snake_case__	(       self		,__UpperCAmelCase     )					->				Any:
													return idx * 2





						def 				snake_case__	(       self		,__UpperCAmelCase     )					->				List[Any]:
													return idx * 2 + 1





						def 				snake_case__	(       self		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase     )					->				int:
													if left_element == right_element:
																				A__	     =							a[left_element - 1]
													else:
																				A__	     =							(left_element + right_element) // 2
																				self.build(self.left(__A     )		,__A		,__A		,__A     )
																				self.build(self.right(__A     )		,mid + 1		,__A		,__A     )
																				A__	     =							max(
																				    self.segment_tree[self.left(__A     )]		,self.segment_tree[self.right(__A     )]     )





						def 				snake_case__	(       self		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase     )					->				List[Any]:
													if self.flag[idx] is True:
																				A__	     =							self.lazy[idx]
																				A__	     =							False
																				if left_element != right_element:
																											A__	     =							self.lazy[idx]
																											A__	     =							self.lazy[idx]
																											A__	     =							True
																											A__	     =							True

													if right_element < a or left_element > b:
																				return True
													if left_element >= a and right_element <= b:
																				A__	     =							val
																				if left_element != right_element:
																											A__	     =							val
																											A__	     =							val
																											A__	     =							True
																											A__	     =							True
																				return True
													A__	     =							(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     )
													A__	     =							max(
													    self.segment_tree[self.left(__A     )]		,self.segment_tree[self.right(__A     )]     )
													return True





						def 				snake_case__	(       self		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase     )					->				List[str]:
													if self.flag[idx] is True:
																				A__	     =							self.lazy[idx]
																				A__	     =							False
																				if left_element != right_element:
																											A__	     =							self.lazy[idx]
																											A__	     =							self.lazy[idx]
																											A__	     =							True
																											A__	     =							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]
													A__	     =							(left_element + right_element) // 2
													A__	     =							self.query(self.left(__A     )		,__A		,__A		,__A		,__A     )
													A__	     =							self.query(self.right(__A     )		,mid + 1		,__A		,__A		,__A     )
													return max(__A		,__A     )





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


if __name__ == "__main__":
				__SCREAMING_SNAKE_CASE											=  [1, 2, -4, 7, 3, -5, 6, 11, -20, 9, 14, 15, 5, 2, -8]
				__SCREAMING_SNAKE_CASE											=  15
				__SCREAMING_SNAKE_CASE											=  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, 1_11)
				print(segt.query(1, 1, size, 1, 15))
				segt.update(1, 1, size, 7, 8, 2_35)
				print(segt)






"""simple docstring"""




from math import cos, sin, sqrt, tau

from audio_filters.iir_filter import IIRFilter






def   UpperCAmelCase					(	UpperCamelCase__       ,    UpperCamelCase__       ,    UpperCamelCase__ = 1 / sqrt(2				)				):






							"""simple docstring"""





							A__	     =							tau * frequency / samplerate
							A__	     =							sin(UpperCamelCase__				)
							A__	     =							cos(UpperCamelCase__				)
							A__	     =							_sin / (2 * q_factor)

							A__	     =							(1 - _cos) / 2
							A__	     =							1 - _cos

							A__	     =							1 + alpha
							A__	     =							-2 * _cos
							A__	     =							1 - alpha

							A__	     =							IIRFilter(2				)
							filt.set_coefficients([aa, aa, aa]       ,    [ba, ba, ba]				)
							return filt






def   UpperCAmelCase					(	UpperCamelCase__       ,    UpperCamelCase__       ,    UpperCamelCase__ = 1 / sqrt(2				)				):






							"""simple docstring"""





							A__	     =							tau * frequency / samplerate
							A__	     =							sin(UpperCamelCase__				)
							A__	     =							cos(UpperCamelCase__				)
							A__	     =							_sin / (2 * q_factor)

							A__	     =							(1 + _cos) / 2
							A__	     =							-1 - _cos

							A__	     =							1 + alpha
							A__	     =							-2 * _cos
							A__	     =							1 - alpha

							A__	     =							IIRFilter(2				)
							filt.set_coefficients([aa, aa, aa]       ,    [ba, ba, ba]				)
							return filt






def   UpperCAmelCase					(	UpperCamelCase__       ,    UpperCamelCase__       ,    UpperCamelCase__ = 1 / sqrt(2				)				):






							"""simple docstring"""





							A__	     =							tau * frequency / samplerate
							A__	     =							sin(UpperCamelCase__				)
							A__	     =							cos(UpperCamelCase__				)
							A__	     =							_sin / (2 * q_factor)

							A__	     =							_sin / 2
							A__	     =							0
							A__	     =							-ba

							A__	     =							1 + alpha
							A__	     =							-2 * _cos
							A__	     =							1 - alpha

							A__	     =							IIRFilter(2				)
							filt.set_coefficients([aa, aa, aa]       ,    [ba, ba, ba]				)
							return filt






def   UpperCAmelCase					(	UpperCamelCase__       ,    UpperCamelCase__       ,    UpperCamelCase__ = 1 / sqrt(2				)				):






							"""simple docstring"""





							A__	     =							tau * frequency / samplerate
							A__	     =							sin(UpperCamelCase__				)
							A__	     =							cos(UpperCamelCase__				)
							A__	     =							_sin / (2 * q_factor)

							A__	     =							1 - alpha
							A__	     =							-2 * _cos
							A__	     =							1 + alpha

							A__	     =							IIRFilter(2				)
							filt.set_coefficients([ba, ba, ba]       ,    [ba, ba, ba]				)
							return filt






def   UpperCAmelCase					(	UpperCamelCase__       ,    UpperCamelCase__       ,    UpperCamelCase__       ,    UpperCamelCase__ = 1 / sqrt(2				)       ,    ):






							"""simple docstring"""





							A__	     =							tau * frequency / samplerate
							A__	     =							sin(UpperCamelCase__				)
							A__	     =							cos(UpperCamelCase__				)
							A__	     =							_sin / (2 * q_factor)
							A__	     =							10 ** (gain_db / 40)

							A__	     =							1 + alpha * big_a
							A__	     =							-2 * _cos
							A__	     =							1 - alpha * big_a
							A__	     =							1 + alpha / big_a
							A__	     =							-2 * _cos
							A__	     =							1 - alpha / big_a

							A__	     =							IIRFilter(2				)
							filt.set_coefficients([aa, aa, aa]       ,    [ba, ba, ba]				)
							return filt






def   UpperCAmelCase					(	UpperCamelCase__       ,    UpperCamelCase__       ,    UpperCamelCase__       ,    UpperCamelCase__ = 1 / sqrt(2				)       ,    ):






							"""simple docstring"""





							A__	     =							tau * frequency / samplerate
							A__	     =							sin(UpperCamelCase__				)
							A__	     =							cos(UpperCamelCase__				)
							A__	     =							_sin / (2 * q_factor)
							A__	     =							10 ** (gain_db / 40)
							A__	     =							(big_a + 1) - (big_a - 1) * _cos
							A__	     =							(big_a + 1) + (big_a - 1) * _cos
							A__	     =							(big_a - 1) - (big_a + 1) * _cos
							A__	     =							(big_a - 1) + (big_a + 1) * _cos
							A__	     =							2 * sqrt(UpperCamelCase__				) * alpha

							A__	     =							big_a * (pmc + aaa)
							A__	     =							2 * big_a * mpc
							A__	     =							big_a * (pmc - aaa)
							A__	     =							ppmc + aaa
							A__	     =							-2 * pmpc
							A__	     =							ppmc - aaa

							A__	     =							IIRFilter(2				)
							filt.set_coefficients([aa, aa, aa]       ,    [ba, ba, ba]				)
							return filt






def   UpperCAmelCase					(	UpperCamelCase__       ,    UpperCamelCase__       ,    UpperCamelCase__       ,    UpperCamelCase__ = 1 / sqrt(2				)       ,    ):






							"""simple docstring"""





							A__	     =							tau * frequency / samplerate
							A__	     =							sin(UpperCamelCase__				)
							A__	     =							cos(UpperCamelCase__				)
							A__	     =							_sin / (2 * q_factor)
							A__	     =							10 ** (gain_db / 40)
							A__	     =							(big_a + 1) - (big_a - 1) * _cos
							A__	     =							(big_a + 1) + (big_a - 1) * _cos
							A__	     =							(big_a - 1) - (big_a + 1) * _cos
							A__	     =							(big_a - 1) + (big_a + 1) * _cos
							A__	     =							2 * sqrt(UpperCamelCase__				) * alpha

							A__	     =							big_a * (ppmc + aaa)
							A__	     =							-2 * big_a * pmpc
							A__	     =							big_a * (ppmc - aaa)
							A__	     =							pmc + aaa
							A__	     =							2 * mpc
							A__	     =							pmc - aaa

							A__	     =							IIRFilter(2				)
							filt.set_coefficients([aa, aa, aa]       ,    [ba, ba, ba]				)
							return filt





