Cod sursa(job #2628169)
| Utilizator | Data | 14 iunie 2020 18:29:07 | |
|---|---|---|---|
| Problema | Cautare binara | Scor | 0 |
| Compilator | py | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
from bisect import bisect_left, bisect_right
with open("date.in", "r") as f, open("date.out", "w") as g:
n, a, m = int(next(f)), list(int(i) for i in next(f).split()), int(next(f))
bl, br = bisect_left, bisect_right
for i in range(m):
o, x = (int(i) for i in next(f).split())
if o == 0:
poz = br(a, x)
g.write(str(poz if poz and a[poz - 1] == x else -1))
elif o == 1:
g.write(str(br(a, x)))
else:
g.write(str(bl(a, x) + 1))
g.write('\n')
