Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.04 s | 3 KBi |
#2 |
Correcto
|
0.026 s | 3 KBi |
#3 |
Correcto
|
0.089 s | 3 KBi |
#4 |
Correcto
|
0.993 s | 8 KBi |
#5 |
Correcto
|
1.416 s | 9 KBi |
#6 |
Tiempo límite excedido
|
1.559 s | 21 KBi |
#7 |
Tiempo límite excedido
|
1.589 s | 21 KBi |
#8 |
Correcto
|
1.461 s | 21 KBi |
from collections import defaultdict from bisect import bisect_right, bisect_left _ = input() nums = list(map(int, input().split(" "))) snums = sorted(set(nums)) # try lists instead of maps, maybe it'll go faster m = [[] for _ in range(len(snums))] for i, n in enumerate(nums): bisect_left m[bisect_left(snums, n)].append(i) Q = int(input()) for _ in range(Q): L, R, X = map(int, input().split(" ")) i = bisect_left(snums, X) if i < len(snums) and snums[i] == X: l = m[i] print(bisect_right(l, R) - bisect_right(l, L - 1)) else: print(0)