Pagini recente » Cod sursa (job #1981550) | Cod sursa (job #2410875) | Cod sursa (job #973015) | Cod sursa (job #1250508) | Cod sursa (job #196631)
Cod sursa(job #196631)
var f,g:text;
a:array[1..100000]of longint;
n,m,i,poz,x,op,c,st,dr:longint;
begin
assign(f,'cautbin.in');reset(f);
assign(g,'cautbin.out');rewrite(g);
read(f,n);
for i:=1 to n do read(f,a[i]);
read(f,m);
for i:=1 to m do begin
read(f,op,x);
st:=1;
dr:=n;
poz:=0;
while (st<=dr)and(poz=0) do begin
c:=st+(dr-st)div 2;
if x<a[c] then dr:=c-1;
if x>a[c] then st:=c+1;
if x=a[c] then poz:=c;
end;
if poz<>0 then begin
if op=0 then begin
while x=a[poz+1] do inc(poz);
writeln(g,poz);
end;
if op=1 then writeln(g,poz-1);
if op=2 then writeln(g,poz+1);
end;
if poz=0 then begin
if op=0 then writeln(g,'-1');
if op=1 then begin
poz:=dr;
writeln(g,poz);
end;
if op=2 then begin
poz:=st;
writeln(g,poz);
end;
end;
end;
close(f);
close(g);
end.