P3381: [Usaco2004 Open]Cave Cows 2 洞穴里的牛之二

时间:2023-03-09 20:04:08
P3381: [Usaco2004 Open]Cave Cows 2 洞穴里的牛之二

这题。。思维上远没有上一题复杂,是一个裸的RMQ。。利用倍增就可以解决了。

 var n,q,i,j,f,t,c:longint;
a:array[..,..] of longint;
function min(a,b:longint):longint;
begin
if a>b then exit(b)
else exit(a);
end;
begin
readln(n,q);
for i:= to n do
readln(a[,i]);
for i:= to trunc(ln(n)/ln())+ do
for j:= to n-( shl i)+ do
a[i,j]:=min(a[i-,j],a[i-,j+( shl (i-))]);
for i:= to q do
begin
readln(f,t);
c:=trunc(ln(t-f+)/ln());
writeln(min(a[c,f],a[c,t-( shl c)+]));
end;
end.

(转载请注明出处:http://www.cnblogs.com/Kalenda/)