很不幸,这题我又被虐了,给个链接http://www.cnblogs.com/g-word/p/3288675.html

 1 var p:array[0..20] of longint;
 2     f:array[0..200010,0..20] of longint;
 3     mx,b,d,v:array[0..200010] of longint;
 4     i,j,n,k:longint;
 5     ans,s:double;
 6 
 7 function min(a,b:longint):longint;
 8   begin
 9     if a>b then exit(b) else exit(a);
10   end;
11 
12 function ask(l,r:longint):longint;
13   begin
14     k:=trunc(ln(r-l+1)/ln(2)+0.0001);
15     exit(min(f[l,k],f[r-p[k]+1,k]));
16   end;
17 
18 begin
19   readln(n);
20   for i:=1 to n do
21     read(d[i]);
22   for i:=1 to n do
23   begin
24     read(b[i]);
25     v[b[i]]:=i;
26   end;
27   for i:=1 to n do
28     d[i]:=v[d[i]];
29   for i:=1 to n do
30   begin
31     v[d[i]]:=i;
32     if mx[i-1]>d[i] then mx[i]:=mx[i-1] else mx[i]:=d[i];
33     f[i,0]:=d[i];
34   end;
35   k:=trunc(ln(n)/ln(2)+0.1);
36   p[0]:=1;
37   for i:=1 to k do
38     p[i]:=p[i-1]*2;
39   for j:=1 to k do
40     for i:=1 to n do
41       if i+p[j]-1<=n then
42         f[i,j]:=min(f[i,j-1],f[i+p[j-1],j-1])
43       else break;
44   ans:=1;
45   for i:=1 to n-1 do
46     if (i=1) or (v[i]>v[i+1]) then ans:=ans+1+s
47     else if (v[i+1]=v[i]+1) and (mx[v[i]]<=i+1) then s:=s+0.5
48     else if ask(v[i],v[i+1])<i then s:=0;
49   ans:=ans+s;
50   writeln(ans-0.001:0:3);
51   writeln(ans:0:3);
52   writeln(ans+0.001:0:3);
53 end.
View Code

 

posted on 2015-06-30 16:12  acphile  阅读(135)  评论(0编辑  收藏  举报