var a: array [1..100000] of longint; dp: array [1..100000, 0..20] of longint; n, i: longint;
functionmin(x, y: longint): longint; begin if x < y thenexit(x) elseexit(y); end;
procedureinit; var i, j: longint; begin for i := 1to n do dp[i, 0] := a[i]; j := 1; while1<<j-1<=n do begin for i := 1to n-1<<(j-1) do dp[i, j] := min(dp[i, j-1], dp[i+1<<(j-1), j-1]); inc(j); end; end;
functionquery(x, y: longint): longint; var t: longint; begin t := 0; while (1<<(t+1)<=y-x+1) do inc(t); query := min(dp[x][t], dp[y-(1<<t)+1][t]); end;
var x, y: longint;
begin assign(input, 'main.in'); reset(input); assign(output, 'main.out'); rewrite(output);
readln(n); for i := 1to n doread(a[i]); init; whilenot eof do begin read(x, y); writeln(query(X, y)); end;
OOPS!
A comment box should be right here...But it was gone due to network issues :-(If you want to leave comments, make sure you have access to disqus.com.