Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.034 s | 3 KBi |
#2 |
Correcto
|
0.022 s | 3 KBi |
#3 |
Correcto
|
0.08 s | 3 KBi |
#4 |
Correcto
|
0.989 s | 8 KBi |
#5 |
Tiempo límite excedido
|
1.551 s | 9 KBi |
#6 |
Correcto
|
0.995 s | 26 KBi |
#7 |
Tiempo límite excedido
|
1.536 s | 26 KBi |
#8 |
Correcto
|
0.89 s | 26 KBi |
from collections import defaultdict # we aim for the last <= to target def _query(arr, target): if target < 0: return 0 l, r = 0, len(arr) - 1 res = -1 while l <= r: m = (l + r) // 2 if arr[m] <= target: res = m l = m + 1 else: r = m - 1 return res + 1 m = {} _ = input() nums = list(map(int, input().split(" "))) for i, n in enumerate(nums): if n not in m: m[n] = [] m[n].append(i) Q = int(input()) for _ in range(Q): L, R, X = map(int, input().split(" ")) if X not in m: print(0) else: l = m[X] print(_query(l, R) - _query(l, L - 1))