
"""simple docstring"""




from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


a		:					Optional[int]    	=					{
    'configuration_openai': ['OPENAI_GPT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'OpenAIGPTConfig'],
    'tokenization_openai': ['OpenAIGPTTokenizer'],
}

try:
    if not is_tokenizers_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    a		:					List[str]    	=					['OpenAIGPTTokenizerFast']

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    a		:					Optional[Any]    	=					[
        'OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST',
        'OpenAIGPTDoubleHeadsModel',
        'OpenAIGPTForSequenceClassification',
        'OpenAIGPTLMHeadModel',
        'OpenAIGPTModel',
        'OpenAIGPTPreTrainedModel',
        'load_tf_weights_in_openai_gpt',
    ]

try:
    if not is_tf_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    a		:					str    	=					[
        'TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST',
        'TFOpenAIGPTDoubleHeadsModel',
        'TFOpenAIGPTForSequenceClassification',
        'TFOpenAIGPTLMHeadModel',
        'TFOpenAIGPTMainLayer',
        'TFOpenAIGPTModel',
        'TFOpenAIGPTPreTrainedModel',
    ]


if TYPE_CHECKING:
    from .configuration_openai import OPENAI_GPT_PRETRAINED_CONFIG_ARCHIVE_MAP, OpenAIGPTConfig
    from .tokenization_openai import OpenAIGPTTokenizer

    try:
        if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .tokenization_openai_fast import OpenAIGPTTokenizerFast

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_openai import (
            OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
            OpenAIGPTDoubleHeadsModel,
            OpenAIGPTForSequenceClassification,
            OpenAIGPTLMHeadModel,
            OpenAIGPTModel,
            OpenAIGPTPreTrainedModel,
            load_tf_weights_in_openai_gpt,
        )

    try:
        if not is_tf_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_tf_openai import (
            TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
            TFOpenAIGPTDoubleHeadsModel,
            TFOpenAIGPTForSequenceClassification,
            TFOpenAIGPTLMHeadModel,
            TFOpenAIGPTMainLayer,
            TFOpenAIGPTModel,
            TFOpenAIGPTPreTrainedModel,
        )

else:
    import sys

    a		:					Optional[Any]    	=					_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)




"""simple docstring"""




import math







class 						lowercase:



     def __init__(       self    ,							__SCREAMING_SNAKE_CASE      )		->    Optional[int]:







         """simple docstring"""



         a__    = len(__SCREAMING_SNAKE_CASE      )
         a__    = [0] * (
             4 * self.N
         )  # approximate the overall size of segment tree with array N
         self.build(1    ,							0    ,							self.N - 1      )



     def  lowercase__     (       self    ,							__SCREAMING_SNAKE_CASE      )		->    Optional[Any]:







         """simple docstring"""



         return idx * 2



     def  lowercase__     (       self    ,							__SCREAMING_SNAKE_CASE      )		->    Optional[int]:







         """simple docstring"""



         return idx * 2 + 1



     def  lowercase__     (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )		->    List[str]:  # noqa: E741







         """simple docstring"""



         if l == r:
             a__    = A[l]
         else:
             a__    = (l + r) // 2
             self.build(self.left(__SCREAMING_SNAKE_CASE      )    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )
             self.build(self.right(__SCREAMING_SNAKE_CASE      )    ,							mid + 1    ,							__SCREAMING_SNAKE_CASE      )
             a__    = max(self.st[self.left(__SCREAMING_SNAKE_CASE      )]    ,							self.st[self.right(__SCREAMING_SNAKE_CASE      )]      )



     def  lowercase__     (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )		->    int:







         """simple docstring"""



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



     def  lowercase__     (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )		->    Optional[int]:  # noqa: E741







         """simple docstring"""



         if r < a or l > b:
             return True
         if l == r:
             a__    = val
             return True
         a__    = (l + r) // 2
         self.update_recursive(self.left(__SCREAMING_SNAKE_CASE      )    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )
         self.update_recursive(self.right(__SCREAMING_SNAKE_CASE      )    ,							mid + 1    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )
         a__    = max(self.st[self.left(__SCREAMING_SNAKE_CASE      )]    ,							self.st[self.right(__SCREAMING_SNAKE_CASE      )]      )
         return True



     def  lowercase__     (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )		->    List[str]:







         """simple docstring"""



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



     def  lowercase__     (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )		->    Any:  # noqa: E741







         """simple docstring"""



         if r < a or l > b:
             return -math.inf
         if l >= a and r <= b:
             return self.st[idx]
         a__    = (l + r) // 2
         a__    = self.query_recursive(self.left(__SCREAMING_SNAKE_CASE      )    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )
         a__    = self.query_recursive(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  lowercase__     (       self      )		->    List[Any]:







         """simple docstring"""



         a__    = []
         for i in range(1    ,							N + 1      ):
             show_list += [self.query(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )]
         print(__SCREAMING_SNAKE_CASE      )


if __name__ == "__main__":
    a		:					Union[str, Any]    	=					[1, 2, -4, 7, 3, -5, 6, 11, -20, 9, 14, 15, 5, 2, -8]
    a		:					Dict    	=					15
    a		:					Tuple    	=					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()


