1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| #include<bits/stdc++.h> using namespace std; #define int long long inline int read(){int x=0,f=1;char ch=getchar(); while(ch<'0'|| ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;} #define Z(x) (x)*(x) #define pb push_back
#define N 5010 #define M 100010
struct asfsfasfdsaf { int l, r; }b[N]; struct node { int x, y, id, op; }c[N<<2]; int n, m, i, j, k, T; int Log2[M], f[M][22], st[N], top, q; int z[M], a[M]; double dp[N][N], p[N], ans; vector<int>G[N];
bool cmp(node x, node y) { if(x.x==y.x) { if(x.op==y.op) { if(x.op==1) return x.y>y.y; else return x.y<y.y; } return x.op<y.op; } return x.x<y.x; }
int Mx(int l, int r) { int k=Log2[r-l+1]; return max(f[l][k], f[r-(1<<k)+1][k]); }
int re(int x) { if(x>q) return q; return x; }
void dfs(int x) { int i, j;
for(int y : G[x]) dfs(y); for(int y : G[x]) { dp[x][0]*=dp[y][re(st[x]-st[y])];
}
for(i=1; i<=q; ++i) { double p1=1, p2=1; for(int y : G[x]) { p1*=dp[y][re(i+st[x]-st[y]-1)]; p2*=dp[y][re(i+st[x]-st[y])]; } dp[x][i]=p[x]*p1+(1-p[x])*p2;
}
}
signed main() {
n=read(); q=read(); for(i=1; i<=n; ++i) a[i]=read(), f[i][0]=a[i]; for(k=1; k<=20; ++k) for(i=1, j=1+(1<<k-1); i+(1<<k)-1<=n; ++i, ++j) { f[i][k]=max(f[i][k-1], f[j][k-1]); } for(i=2; i<=n; ++i) Log2[i]=Log2[i>>1]+1; for(i=1, k=0; i<=q; ++i) { b[i].l=read(); b[i].r=read(); scanf("%lf", &p[i]); st[i]=Mx(b[i].l, b[i].r); c[++k]={b[i].l, b[i].r, i, 1}; c[++k]={b[i].r, b[i].l, i, 2}; } st[q+1]=Mx(1, n); b[q+1].l=1; b[q+1].r=n; sort(c+1, c+2*q+1, cmp); z[top=0]=q+1; for(i=1; i<=2*q; ++i) {
if(c[i].op==2) --top; else G[z[top]].pb(c[i].id), z[++top]=c[i].id; } for(i=1; i<=q+1; ++i) dp[i][0]=1-p[i];
dfs(q+1); ans=(double)st[q+1]*dp[q+1][0]; for(i=1; i<=q; ++i) {
ans+=(double)(st[q+1]+i)*(dp[q+1][i]-dp[q+1][i-1]); } printf("%.8lf", ans); return 0; }
|