Feel the idea is interesting W
This is the w:http://www.cnblogs.com/icyf/p/4641564.html.
1#include <cstdio>2#include <cstdlib>3#include <iostream>4 #defineMAXN 2000105 using namespacestd;6 intN;7 intD[MAXN], B[MAXN], MAP[MAXN], S[MAXN], DA[MAXN], FL[MAXN], POS[MAXN];8 9 voidReadint&a) {TenA =0;Charc =GetChar (); One while(C <'0'|| C >'9') C =GetChar (); A while(c >='0'&& C <='9') A = A *Ten+ C'0', C =GetChar (); - } - the voidRead_data () { - read (n); - for(inti =1; I <= N; i++) read (D[i]); - for(inti =1; I <= N; i++) read (B[i]), map[b[i]] =i; + for(inti =1; I <= N; i++) D[i] =Map[d[i]]; - for(inti =1; I <= N; i++) Pos[d[i] =i; + } A at voidSolve () { -da[1] =1, s[1] =1, ++fl[1],--fl[2]; - for(inti =1; I < n; i++) { - if(Pos[i] > pos[i+1]) Da[i] =1, ++fl[i],--fl[i+1]; -S[i] = s[i-1]+Da[i]; - } in for(inti =1; I < n; i++) { - if(D[i] > d[i+1])Continue; to intt = s[d[i+1]-1]-s[d[i]-1]; + if(t) ++fl[d[i]],--fl[d[i+1]]; - } the intFlag =0; * DoubleAns =0.0; $ for(inti =1; I < n; i++) {Panax NotoginsengFlag + =Fl[i]; - if(flag) ans + = (Double) da[i]; the ElseAns + =0.5; + } Aprintf"%.3f\n", ans +0.999); theprintf"%.3f\n", ans +1.000); +printf"%.3f\n", ans +1.001); - } $ $ intMain () - { -Freopen ("count.in","R", stdin); theFreopen ("Count.out","W", stdout); - Read_data ();Wuyi Solve (); the fclose (stdin); - fclose (stdout); Wu return 0; -}
[BZOJ3244] Count of [NOI2013] trees