



from __future__ import annotations

import math






class 						__a :



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



	def 		UpperCamelCase							(						self							:    List[str]				,	snake_case_							:    int)->							int:
						return idx * 2



	def 		UpperCamelCase							(						self							:    int				,	snake_case_							:    int)->							int:
						return idx * 2 + 1



	def 		UpperCamelCase							(						self							:    Tuple				,	snake_case_							:    int				,	snake_case_							:    int				,	snake_case_							:    int				,	snake_case_							:    list[int])->							None:
						if left_element == right_element:
											__lowerCAmelCase	   =a[left_element - 1]
						else:
											__lowerCAmelCase	   =(left_element + right_element) // 2
											self.build(self.left(snake_case_)				,	snake_case_				,	snake_case_				,	snake_case_)
											self.build(self.right(snake_case_)				,	mid + 1				,	snake_case_				,	snake_case_)
											__lowerCAmelCase	   =max(
											    self.segment_tree[self.left(snake_case_)]				,	self.segment_tree[self.right(snake_case_)])



	def 		UpperCamelCase							(						self							:    List[Any]				,	snake_case_							:    int				,	snake_case_							:    int				,	snake_case_							:    int				,	snake_case_							:    int				,	snake_case_							:    int				,	snake_case_							:    int)->							bool:
						if self.flag[idx] is True:
											__lowerCAmelCase	   =self.lazy[idx]
											__lowerCAmelCase	   =False
											if left_element != right_element:
																__lowerCAmelCase	   =self.lazy[idx]
																__lowerCAmelCase	   =self.lazy[idx]
																__lowerCAmelCase	   =True
																__lowerCAmelCase	   =True

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



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



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


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









import os
from typing import Dict, List, Tuple, TypeVar, Union


lowercase_	       =			TypeVar('''T''')

lowercase_	       =			Union[List[T], Tuple[T, ...]]
lowercase_	       =			Union[T, List[T], Dict[str, T]]
lowercase_	       =			Union[str, bytes, os.PathLike]




