



from __future__ import annotations

from collections.abc import Callable
from typing import Any, Generic, TypeVar

a__   :					Optional[int] 						=      TypeVar("T")



class    UpperCAmelCase__(				Generic[T]						):

   '''simple docstring'''




   def __init__(    self	:      List[str]      ,					lowerCAmelCase	:      list[T]      ,					lowerCAmelCase	:      Callable[[T, T], T])						->					None:




         """simple docstring"""

         lowercase__  =	None

         lowercase__  =	len(lowerCAmelCase)
         lowercase__  =	[any_type for _ in range(self.N)] + arr
         lowercase__  =	fnc
         self.build()


   def       UpperCAmelCase		(    self	:      str)						->					None:




         """simple docstring"""

         for p in range(self.N - 1      ,					0      ,					-1):
               lowercase__  =	self.fn(self.st[p * 2]      ,					self.st[p * 2 + 1])


   def       UpperCAmelCase		(    self	:      Dict      ,					lowerCAmelCase	:      int      ,					lowerCAmelCase	:      T)						->					None:




         """simple docstring"""

         p += self.N
         lowercase__  =	v
         while p > 1:
               lowercase__  =	p // 2
               lowercase__  =	self.fn(self.st[p * 2]      ,					self.st[p * 2 + 1])



   def       UpperCAmelCase		(    self	:      List[Any]      ,					lowerCAmelCase	:      int      ,					lowerCAmelCase	:      int)						->					T | None:  # noqa: E741




         """simple docstring"""

         lowercase__,						lowercase__  =	l + self.N, r + self.N

         lowercase__  =	None
         while l <= r:
               if l % 2 == 1:
                     lowercase__  =	self.st[l] if res is None else self.fn(lowerCAmelCase      ,					self.st[l])
               if r % 2 == 0:
                     lowercase__  =	self.st[r] if res is None else self.fn(lowerCAmelCase      ,					self.st[r])
               lowercase__,						lowercase__  =	(l + 1) // 2, (r - 1) // 2
         return res


if __name__ == "__main__":
       from functools import reduce

       a__   :					List[Any] 						=      [1, 10, -2, 9, -3, 8, 4, -7, 5, 6, 11, -12]

       a__   :					Optional[int] 						=      {
           0: 7,
           1: 2,
           2: 6,
           3: -14,
           4: 5,
           5: 4,
           6: 7,
           7: -10,
           8: 9,
           9: 10,
           10: 12,
           11: 1,
       }

       a__   :					Dict 						=      SegmentTree(test_array, min)
       a__   :					Tuple 						=      SegmentTree(test_array, max)
       a__   :					Optional[Any] 						=      SegmentTree(test_array, lambda a, b: a + b)

       def 	_lowerCAmelCase (    ):
             for i in range(len(A__						)						):
                   for j in range(A__    ,	len(A__						)						):
                         lowercase__  =	reduce(A__    ,	test_array[i : j + 1]						)
                         lowercase__  =	reduce(A__    ,	test_array[i : j + 1]						)
                         lowercase__  =	reduce(lambda A__    ,	A__						: a + b    ,	test_array[i : j + 1]						)
                         assert min_range == min_segment_tree.query(A__    ,	A__						)
                         assert max_range == max_segment_tree.query(A__    ,	A__						)
                         assert sum_range == sum_segment_tree.query(A__    ,	A__						)

       test_all_segments()

       for index, value in test_updates.items():
              a__   :					Any 						=      value
              min_segment_tree.update(index, value)
              max_segment_tree.update(index, value)
              sum_segment_tree.update(index, value)
              test_all_segments()





import pytest
import requests

from datasets.utils.file_utils import http_head

from .utils import OfflineSimulationMode, RequestWouldHangIndefinitelyError, offline

@pytest.mark.integration
def 	_lowerCAmelCase (    ):
      with offline(OfflineSimulationMode.CONNECTION_TIMES_OUT						):
            with pytest.raises(A__						):
                  requests.request('GET'    ,	'https://huggingface.co'						)
            with pytest.raises(requests.exceptions.ConnectTimeout						):
                  requests.request('GET'    ,	'https://huggingface.co'    ,	timeout=1.0						)

@pytest.mark.integration
def 	_lowerCAmelCase (    ):
      with offline(OfflineSimulationMode.CONNECTION_FAILS						):
            with pytest.raises(requests.exceptions.ConnectionError						):
                  requests.request('GET'    ,	'https://huggingface.co'						)

def 	_lowerCAmelCase (    ):
      with offline(OfflineSimulationMode.HF_DATASETS_OFFLINE_SET_TO_1						):
            with pytest.raises(A__						):
                  http_head('https://huggingface.co'						)
