Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.018 s | 3 KBi |
#2 |
Correcto
|
0.011 s | 3 KBi |
#3 |
Correcto
|
0.036 s | 3 KBi |
#4 |
Correcto
|
0.291 s | 8 KBi |
#5 |
Correcto
|
0.903 s | 11 KBi |
#6 |
Correcto
|
0.389 s | 29 KBi |
#7 |
Correcto
|
0.5 s | 29 KBi |
#8 |
Correcto
|
0.436 s | 29 KBi |
def search(arr, x): left = 0 right = len(arr) - 1 res = -1 while left <= right: middle = (left + right) // 2 if arr[middle] <= x: left = middle + 1 res = middle else: right = middle - 1 return res + 1 N = input() arr = input().split(' ') times = int(input()) mem = {} for i, elem in enumerate(arr): if elem not in mem: mem[elem] = [] mem[elem].append(i) # print(mem) for i in range(times): case = input().split(' ') l = int(case[0]) r = int(case[1]) q = case[2] count = 0 if q not in mem: print(0) continue indexes = mem[q] leftIndex = search(indexes, l-1) rightIndex = search(indexes, r) # print(f'>> {leftIndex} {rightIndex} ---- {rightIndex - leftIndex}') print(rightIndex - leftIndex)