






import math
class 							__snake_case:



 def __init__(						self : Optional[int]			,		UpperCAmelCase__ : Optional[Any]						):

    """simple docstring"""






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



 def     UpperCAmelCase     (						self : Any			,		UpperCAmelCase__ : Optional[Any]						):

    """simple docstring"""






    return idx * 2



 def     UpperCAmelCase     (						self : Tuple			,		UpperCAmelCase__ : List[str]						):

    """simple docstring"""






    return idx * 2 + 1



 def     UpperCAmelCase     (						self : Tuple			,		UpperCAmelCase__ : List[Any]			,		UpperCAmelCase__ : Dict			,		UpperCAmelCase__ : List[str]						):  # noqa: E741

    """simple docstring"""






    if l == r:
       lowercase__    :						Optional[Any]       =			A[l]
    else:
       lowercase__    :						Union[str, Any]       =			(l + r) // 2
       self.build(self.left(UpperCAmelCase__						)			,		UpperCAmelCase__			,		UpperCAmelCase__						)
       self.build(self.right(UpperCAmelCase__						)			,		mid + 1			,		UpperCAmelCase__						)
       lowercase__    :						Union[str, Any]       =			max(self.st[self.left(UpperCAmelCase__						)]			,		self.st[self.right(UpperCAmelCase__						)]						)



 def     UpperCAmelCase     (						self : Dict			,		UpperCAmelCase__ : Union[str, Any]			,		UpperCAmelCase__ : Optional[int]			,		UpperCAmelCase__ : Union[str, Any]						):

    """simple docstring"""






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



 def     UpperCAmelCase     (						self : Optional[int]			,		UpperCAmelCase__ : Dict			,		UpperCAmelCase__ : List[str]			,		UpperCAmelCase__ : Optional[int]			,		UpperCAmelCase__ : Optional[int]			,		UpperCAmelCase__ : str			,		UpperCAmelCase__ : List[Any]						):  # noqa: E741

    """simple docstring"""






    if r < a or l > b:
       return True
    if l == r:
       lowercase__    :						Union[str, Any]       =			val
       return True
    lowercase__    :						Optional[Any]       =			(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__						)
    lowercase__    :						List[Any]       =			max(self.st[self.left(UpperCAmelCase__						)]			,		self.st[self.right(UpperCAmelCase__						)]						)
    return True



 def     UpperCAmelCase     (						self : Dict			,		UpperCAmelCase__ : List[str]			,		UpperCAmelCase__ : Tuple						):

    """simple docstring"""






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



 def     UpperCAmelCase     (						self : List[Any]			,		UpperCAmelCase__ : List[Any]			,		UpperCAmelCase__ : Union[str, Any]			,		UpperCAmelCase__ : Tuple			,		UpperCAmelCase__ : str			,		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]
    lowercase__    :						int       =			(l + r) // 2
    lowercase__    :						int       =			self.query_recursive(self.left(UpperCAmelCase__						)			,		UpperCAmelCase__			,		UpperCAmelCase__			,		UpperCAmelCase__			,		UpperCAmelCase__						)
    lowercase__    :						str       =			self.query_recursive(self.right(UpperCAmelCase__						)			,		mid + 1			,		UpperCAmelCase__			,		UpperCAmelCase__			,		UpperCAmelCase__						)
    return max(UpperCAmelCase__			,		UpperCAmelCase__						)







 def     UpperCAmelCase     (						self : Optional[int]						):

    """simple docstring"""






    lowercase__    :						int       =			[]
    for i in range(1			,		N + 1						):
       show_list += [self.query(UpperCAmelCase__			,		UpperCAmelCase__						)]
    print(UpperCAmelCase__						)


if __name__ == "__main__":
 a 			=							[1, 2, -4, 7, 3, -5, 6, 11, -20, 9, 14, 15, 5, 2, -8]
 a 			=							15
 a 			=							SegmentTree(A)
 print(segt.query(4, 6))
 print(segt.query(7, 11))
 print(segt.query(7, 12))
 segt.update(1, 3, 111)
 print(segt.query(1, 15))
 segt.update(7, 8, 235)
 segt.show_data()









import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers.testing_utils import require_vision
from transformers.utils import is_vision_available


if is_vision_available():
       from PIL import Image

       from transformers import AutoProcessor, BertTokenizer, CLIPImageProcessor, GitProcessor, PreTrainedTokenizerFast

@require_vision
class 			__A(    unittest.TestCase			):

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    tempfile.mkdtemp()

            _UpperCamelCase														=    CLIPImageProcessor()
            _UpperCamelCase														=    BertTokenizer.from_pretrained(
                '''hf-internal-testing/tiny-random-BertModel''',							model_input_names=['''input_ids''', '''attention_mask''']   )

            _UpperCamelCase														=    GitProcessor(A,							A   )

            processor.save_pretrained(self.tmpdirname   )

     def 						_UpperCamelCase  (   self,							**A   ):





            """simple docstring"""

            return AutoProcessor.from_pretrained(self.tmpdirname,							**A   ).tokenizer

     def 						_UpperCamelCase  (   self,							**A   ):





            """simple docstring"""

            return AutoProcessor.from_pretrained(self.tmpdirname,							**A   ).image_processor

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            shutil.rmtree(self.tmpdirname   )

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    [np.random.randint(255,							size=(3, 30, 400),							dtype=np.uinta   )]

            _UpperCamelCase														=    [Image.fromarray(np.moveaxis(A,							0,							-1   )   ) for x in image_inputs]

            return image_inputs

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    GitProcessor(tokenizer=self.get_tokenizer(),							image_processor=self.get_image_processor()   )
            processor.save_pretrained(self.tmpdirname   )

            _UpperCamelCase														=    self.get_tokenizer(bos_token='''(BOS)''',							eos_token='''(EOS)'''   )
            _UpperCamelCase														=    self.get_image_processor(do_normalize=A,							padding_value=1.0   )

            _UpperCamelCase														=    GitProcessor.from_pretrained(
                self.tmpdirname,							bos_token='''(BOS)''',							eos_token='''(EOS)''',							do_normalize=A,							padding_value=1.0   )

            self.assertEqual(processor.tokenizer.get_vocab(),							tokenizer_add_kwargs.get_vocab()   )
            self.assertIsInstance(processor.tokenizer,							A   )

            self.assertEqual(processor.image_processor.to_json_string(),							image_processor_add_kwargs.to_json_string()   )
            self.assertIsInstance(processor.image_processor,							A   )

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    self.get_image_processor()
            _UpperCamelCase														=    self.get_tokenizer()

            _UpperCamelCase														=    GitProcessor(tokenizer=A,							image_processor=A   )

            _UpperCamelCase														=    self.prepare_image_inputs()

            _UpperCamelCase														=    image_processor(A,							return_tensors='''np'''   )
            _UpperCamelCase														=    processor(images=A,							return_tensors='''np'''   )

            for key in input_feat_extract.keys():
                   self.assertAlmostEqual(input_feat_extract[key].sum(),							input_processor[key].sum(),							delta=1E-2   )

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    self.get_image_processor()
            _UpperCamelCase														=    self.get_tokenizer()

            _UpperCamelCase														=    GitProcessor(tokenizer=A,							image_processor=A   )

            _UpperCamelCase														=    '''lower newer'''

            _UpperCamelCase														=    processor(text=A   )

            _UpperCamelCase														=    tokenizer(A,							return_token_type_ids=A   )

            for key in encoded_tok.keys():
                   self.assertListEqual(encoded_tok[key],							encoded_processor[key]   )

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    self.get_image_processor()
            _UpperCamelCase														=    self.get_tokenizer()

            _UpperCamelCase														=    GitProcessor(tokenizer=A,							image_processor=A   )

            _UpperCamelCase														=    '''lower newer'''
            _UpperCamelCase														=    self.prepare_image_inputs()

            _UpperCamelCase														=    processor(text=A,							images=A   )

            self.assertListEqual(list(inputs.keys()   ),							['''input_ids''', '''attention_mask''', '''pixel_values''']   )

            # test if it raises when no input is passed
            with pytest.raises(A   ):
                   processor()

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    self.get_image_processor()
            _UpperCamelCase														=    self.get_tokenizer()

            _UpperCamelCase														=    GitProcessor(tokenizer=A,							image_processor=A   )

            _UpperCamelCase														=    [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

            _UpperCamelCase														=    processor.batch_decode(A   )
            _UpperCamelCase														=    tokenizer.batch_decode(A   )

            self.assertListEqual(A,							A   )



     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    self.get_image_processor()
            _UpperCamelCase														=    self.get_tokenizer()

            _UpperCamelCase														=    GitProcessor(tokenizer=A,							image_processor=A   )

            _UpperCamelCase														=    '''lower newer'''
            _UpperCamelCase														=    self.prepare_image_inputs()

            _UpperCamelCase														=    processor(text=A,							images=A   )

            # For now the processor supports only ['input_ids', 'attention_mask', 'pixel_values']
            self.assertListEqual(list(inputs.keys()   ),							['''input_ids''', '''attention_mask''', '''pixel_values''']   )






