Pagini recente » Cod sursa (job #2463884) | Cod sursa (job #2141254) | Cod sursa (job #1385695) | Cod sursa (job #1146969) | Cod sursa (job #2449252)
#!/usr/bin/env python3
import sys
sys.stdout = open('cautbin.out')
with open('cautbin.in', 'r') as f:
readInts = lambda: map(int, f.readline().split())
f.readline()
a = list(readInts())
P = 1
while P << 1 < len(a): P <<= 1
for _ in range(int(f.readline())):
op = tuple(readInts())
if op[0] < 2:
i, p = 0, P
while p:
if i + p < len(a) and a[i + p] <= op[1]:
i += p
p >>= 1
print(i + 1 if a[i] == op[1] or op[0] else -1)
else:
i, p = len(a) - 1, P
while p:
if i - p >= 0 and a[i - p] >= op[1]:
i -= p
p >>= 1
print(i + 1)