Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.027 s | 3 KBi |
#2 |
Correcto
|
0.024 s | 3 KBi |
#3 |
Correcto
|
0.079 s | 4 KBi |
#4 |
Correcto
|
1.085 s | 8 KBi |
#5 |
Tiempo límite excedido
|
1.56 s | 9 KBi |
#6 |
Correcto
|
1.286 s | 43 KBi |
#7 |
Correcto
|
1.177 s | 26 KBi |
#8 |
Correcto
|
1.306 s | 30 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 = defaultdict(list) _ = input() nums = list(map(int, input().split(" "))) for i, n in enumerate(nums): m[n].append(i) Q = int(input()) for _ in range(Q): L, R, X = map(int, input().split(" ")) print(_query(m[X], R) - _query(m[X], L - 1))