Pagini recente » Cod sursa (job #1126738) | Cod sursa (job #1773472) | Cod sursa (job #981243) | Cod sursa (job #1734846) | Cod sursa (job #221880)
Cod sursa(job #221880)
var c,loc,i,n,m,b:longint;
vec:array[1..100000] of longint;
f,f2:text;
a:byte;
function cautbin(st,dr,k:longint):longint;
var mij:longint;
begin
mij:=(st+dr) div 2;
if k=vec[mij] then
begin
while k=vec[mij] do mij:=mij+1;
cautbin:=mij-1;
end
else
begin
if (st>dr) then
begin
cautbin:=-1;
loc:=mij;
end
else
begin
if k<vec[mij] then
begin
cautbin:=cautbin(st,mij-1,k);
end
else
begin
cautbin:=cautbin(mij+1,dr,k);
end;
end;
end;
end;
begin
loc:=0;
assign(f,'cautbin.in');
assign(f2,'cautbin.out');
reset(f);
rewrite(f2);
readln(f,n);
for i:=1 to n do read(f,vec[i]);
readln(f,m);
for i:=1 to m do
begin
read(f,a,b);
if a=0 then writeln(f2,cautbin(1,n,b))
else
begin
c:=cautbin(1,n,b);
if c=-1 then
begin
if a=1 then c:=loc;
if a=2 then c:=loc+1;
end;
writeln(f2,c);
end;
end;
close(f);
close(f2);
writeln(cautbin(1,n,7));
end.