Pagini recente » Cod sursa (job #1892874) | Cod sursa (job #2431878) | Cod sursa (job #1861851) | Cod sursa (job #1229618) | Cod sursa (job #2428841)
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;
z1:=0; z2:=0; z3:=0;
if p=0 then
begin
if t[c]=x then z1:=c;
if t[c]<=x then a:=c+1 else b:=c-1
end;
if p=1 then
begin
if t[c]<=x then z2:=c;
if t[c]<=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.