Pagini recente » Cod sursa (job #2026441) | Cod sursa (job #1118924) | Cod sursa (job #2222455) | Cod sursa (job #949175) | Cod sursa (job #781748)
Cod sursa(job #781748)
uses math;
var f,g:text;
a:array[0..20,1..100000] of integer;
bufin,bufout:array[1..65000] of byte;
n,m,i,x,y,j,b,aux:longint;
x1:integer;
begin
assign (f,'rmq.in'); reset (f);
assign (g,'rmq.out'); rewrite (g);
settextbuf (f,bufin);
settextbuf (g,bufout);
read (f,n,m);
for i:=1 to n do
begin
readln (f,x1);
a[0,i]:=x1;
end;
for i:=1 to trunc (log2(n)) do
for j:=1 to (n-(1 shl (i))+1) do
a[i,j]:=min (a[i-1,j],a[i-1,j+1 shl (i-1)]);
for i:=1 to m do
begin
read (F,x,y);
b:=trunc (log2(y-x+1));
aux:=y-x+1-(1 shl b);
writeln (G,min(a[b,x],a[b,x+aux]));
end;
close (f); close (g);
end.