很不幸,这题我又被虐了,给个链接http://www.cnblogs.com/g-word/p/3288675.html
var p:array[..] of longint;
f:array[..,..] of longint;
mx,b,d,v:array[..] of longint;
i,j,n,k:longint;
ans,s:double; function min(a,b:longint):longint;
begin
if a>b then exit(b) else exit(a);
end; function ask(l,r:longint):longint;
begin
k:=trunc(ln(r-l+)/ln()+0.0001);
exit(min(f[l,k],f[r-p[k]+,k]));
end; begin
readln(n);
for i:= to n do
read(d[i]);
for i:= to n do
begin
read(b[i]);
v[b[i]]:=i;
end;
for i:= to n do
d[i]:=v[d[i]];
for i:= to n do
begin
v[d[i]]:=i;
if mx[i-]>d[i] then mx[i]:=mx[i-] else mx[i]:=d[i];
f[i,]:=d[i];
end;
k:=trunc(ln(n)/ln()+0.1);
p[]:=;
for i:= to k do
p[i]:=p[i-]*;
for j:= to k do
for i:= to n do
if i+p[j]-<=n then
f[i,j]:=min(f[i,j-],f[i+p[j-],j-])
else break;
ans:=;
for i:= to n- do
if (i=) or (v[i]>v[i+]) then ans:=ans++s
else if (v[i+]=v[i]+) and (mx[v[i]]<=i+) then s:=s+0.5
else if ask(v[i],v[i+])<i then s:=;
ans:=ans+s;
writeln(ans-0.001::);
writeln(ans::);
writeln(ans+0.001::);
end.