First question: a request must meet three conditions does not increase the maximum length of the promoter sequence.
) Is the probability of each point comprising a second length satisfying a first request asking :( ask
solution:
For each point built len [2] fa [2] of the array are recorded at the start point / end (say behind) the length of the LIS, fa represents a number corresponding to this embodiment len
First question: dp equation $ dp [i] = max ( dp [j]) + 1 \ \ \ \ time_j <time_i \, h_j \ ge h_i \, v_j \ ge v_i $ and tree-dimensional array ah (Space not enough)
Three conditions -> D Partial Order -> the CDQ partition
H is defined as a first dimension, time for the second dimension, v is the third dimension.
But unlike the previous routine of CDQ template.
Since we want to get a complete and correct the dp [i], known by the equation to use when updating dp [i] complete and correct the dp [j], but it is not updated over time (dp [i] repeatedly been different dp [j] update). Sentence is transferred to meet the topological order of the DAG.
In order to ensure complete and accurate, we take the following order CDQ
- Left recursion to solve the interval
- Update interval with the left and right sections
- Right intervals solve recursive
When updating can guarantee the right dp left interval interval [j] complete and correct (sub-problem solving), and while not difficult to find dp [mid + 1] must be complete and correct, because his side are into transfer, has no j can be used as a left interval to update it.
First, ensure that the first dimension sort monotonous, start CDQ.
Then recursively resolve left interval.
Then transfer across the mid section of, respectively, the left and right interval to time as a key sort, to ensure that each order of time (before merging are used to resolve recursive, so the same intervals were about to ensure orderly, but because of this problem CDQ recursive sequence, merging can not be completed) and for [mid + 1, r] similar merge scan pointer monotone [l, mid], maintaining the third dimension in a tree array.
Seeking title is the longest not rise, but due to poor maintenance of the characteristics Fenwick tree, so all the hv reverse, so monotonic time v h on a unified, for the sake of transformation does not drop the longest sequence.
Len again being the maximum CDQ resulting solution is the first to ask.
The second question:
Statistical prerequisite len [0] + len [1] -1 == answer the first question, -1 remove duplicate calculations themselves. Point does not satisfy the condition of direct output 0.0 .......
The probability of a point $ = \ frac {LIS program through the point number of the total number of LIS Program {}} $
After several $ embodiment of the LIS point = fa [0] * fa [1] $
The total number of programs to spend a row of heavy statistical methods will be counted, so a direct cumulative start / end points can be.
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #define db double 5 #define ll long long 6 #define reg register 7 #define F(i,a,b) for(register int (i)=(a);(i)<=(b);++(i)) 8 using namespace std; 9 const int N=500100; 10 inline int read(); 11 int mx,my; 12 int n,T; 13 int h_lsh[N],v_lsh[N],h_cnt,v_cnt; 14 bool mark[N]; 15 struct BOOM{ 16 int tm,h,v; 17 int len[2]; 18 db fa[2]; 19 }f[N];//,q[N]; 20 struct TR{ 21 int len; 22 db fa; 23 int _time; 24 TR(){clear();} 25 void clear(){len=0,fa=0.0,_time=0;} 26 }t[N]; 27 inline bool cmp(BOOM a,BOOM b) 28 { 29 if(a.h!=b.h) return a.h<b.h; 30 if(a.tm!=b.tm) return a.tm<b.tm; 31 return a.v<b.v; 32 } 33 inline bool cmp1(BOOM a,BOOM b) 34 { 35 return a.tm<b.tm; 36 } 37 inline bool cmp2(BOOM a,BOOM b) 38 { 39 return a.tm>b.tm; 40 } 41 void add(int v,int len,db fa) 42 { 43 while(v<=v_cnt+23) 44 { 45 if(t[v]._time<T) t[v].clear(),t[v]._time=T; 46 if(t[v].len==len) t[v].fa+=fa; 47 else if(t[v].len<len) 48 { 49 t[v].len=len; 50 t[v].fa=fa; 51 } 52 v+=(v&-v); 53 } 54 } 55 void clear(int v) 56 { 57 while(v<=v_cnt+23) 58 { 59 t[v].clear(); 60 v+=(v&-v); 61 } 62 } 63 TR ask(int v) 64 { 65 TR s; 66 while(v) 67 { 68 if(t[v]._time<T) t[v].clear(),t[v]._time=T; 69 if(s.len==t[v].len) s.fa+=t[v].fa; 70 else if(s.len<t[v].len) 71 { 72 s.len=t[v].len; 73 s.fa=t[v].fa; 74 } 75 v-=(v&-v); 76 } 77 return s; 78 } 79 void cdq(int l,int r,int o) 80 { 81 // printf("L=%d R=%d\n",l,r); 82 if(l==r) 83 { 84 // f[l].len[o]=f[l].fa[o]=1; 85 return; 86 } 87 int mid=(l+r)>>1; 88 cdq(l,mid,o); 89 sort(f+l,f+mid+1,cmp1); 90 sort(f+mid+1,f+r+1,cmp1); 91 ++T; 92 int p=l,pl=l,pr=mid+1; 93 F(i,mid+1,r) 94 { 95 while(p<=mid&&f[p].tm<=f[i].tm) 96 { 97 add(f[p].v,f[p].len[o],f[p].fa[o]); 98 ++p; 99 } 100 TR s=ask(f[i].v); 101 ++s.len; 102 if(s.len>f[i].len[o]) 103 { 104 f[i].len[o]=s.len; 105 f[i].fa[o]=s.fa; 106 } 107 else if(s.len==f[i].len[o]) 108 { 109 f[i].fa[o]+=s.fa; 110 } 111 } 112 sort(f+l,f+r+1,cmp); 113 cdq(mid+1,r,o); 114 } 115 int main() 116 { 117 // freopen("data.in","r",stdin); 118 n=read(); 119 F(i,1,n) 120 { 121 f[i].h=h_lsh[i]=read(); 122 f[i].v=v_lsh[i]=read(); 123 f[i].len[0]=f[i].len[1]=f[i].fa[0]=f[i].fa[1]=1; 124 f[i].tm=i; 125 } 126 sort(h_lsh+1,h_lsh+n+1); 127 sort(v_lsh+1,v_lsh+n+1); 128 h_cnt=unique(h_lsh+1,h_lsh+n+1)-h_lsh-1; 129 v_cnt=unique(v_lsh+1,v_lsh+n+1)-v_lsh-1; 130 F(i,1,n) 131 { 132 f[i].h=h_cnt+1-(lower_bound(h_lsh+1,h_lsh+h_cnt+1,f[i].h)-h_lsh); 133 f[i].v=v_cnt+1-(lower_bound(v_lsh+1,v_lsh+v_cnt+1,f[i].v)-v_lsh); 134 // printf("i=%d f[i].v=%d\n",i,f[i].v); 135 } 136 sort(f+1,f+n+1,cmp); 137 // F(i,1,n) 138 // { 139 // printf("i=%d f[i].h=%d f[i].tm=%d f[i].v=%d\n",i,f[i].h,f[i].tm,f[i].v); 140 // } 141 cdq(1,n,0); 142 F(i,1,n) 143 { 144 f[i].h=h_cnt-f[i].h+1; 145 f[i].v=v_cnt-f[i].v+1; 146 f[i].tm=n-f[i].tm+1; 147 } 148 sort(f+1,f+n+1,cmp); 149 // reverse(f+1,f+n+1); 150 cdq(1,n,1); 151 int pt_len=0; 152 db tot=0.0; 153 sort(f+1,f+n+1,cmp2); 154 F(i,1,n) 155 { 156 pt_len=max(pt_len,f[i].len[0]); 157 // printf("%d\n",f[i].len[0]); 158 } 159 F(i,1,n) if(f[i].len[0]==pt_len) tot+=f[i].fa[0]; 160 printf("%d\n",pt_len); 161 F(i,1,n) 162 { 163 // printf("i=%d 正:len=%d fa=%d 反:len=%d fa=%d bj=%d\n",i,f[i].len[0],f[i].fa[0],f[i].len[1],f[i].fa[1],f[i].v); 164 if(f[i].len[0]+f[i].len[1]-1==pt_len) printf("%.5lf ",f[i].fa[0]*f[i].fa[1]/(double)tot); 165 else printf("%.5lf ",0.0); 166 } 167 return 0; 168 } 169 inline int read() 170 { 171 int x=0; 172 char tc=getchar(); 173 while(tc<'0'||tc>'9') tc=getchar(); 174 while(tc>='0'&&tc<='9') x=x*10+tc-48,tc=getchar(); 175 return x; 176 }