Pagini recente » Cod sursa (job #779465) | Cod sursa (job #1229726) | Cod sursa (job #2423039) | Cod sursa (job #2436630) | Cod sursa (job #2428771)
var t:array[1..100005] of longint;
n,m,i,a,b,c,p,z1,z2,z3,x:longint;
begin
//assign(input,'cautbin.in'); reset(input);
//assign(output,'cautbin.out'); rewrite(output);
readln(n);
for i:=1 to n do read(t[i]);
readln(m);
for i:=1 to m do
begin
readln(p,x);
a:=1; b:=n;
while a<=b do
begin
c:=(a+b) div 2;
if p=0 then
begin
if t[c]=x then z1:=c;
if x<=t[c] then a:=c+1 else b:=c-1
end;
if p=1 then
begin
if t[c]<=x then z2:=c;
if x<=x then a:=c+1 else b:=c-1
end;
if p=2 then
begin
if t[c]>=x then z3:=c;
if t[c]>=x then b:=c-1 else a:=c+1
end
end;
if p=0 then
begin
if z1=0 then writeln(-1) else writeln(z1)
end;
if p=1 then writeln(z2);
if p=2 then writeln(z3)
end;
close(input);
close(output)
end.