Pagini recente » Cod sursa (job #3038436) | Cod sursa (job #2644580) | Cod sursa (job #928743) | Cod sursa (job #1423353) | Cod sursa (job #221873)
Cod sursa(job #221873)
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-st) div 2;
if k=vec[mij] then
begin
cautbin:=mij;
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.