func_code_string: #include <bits/stdc++.h>   std::vector<int> dsc[100005];   int st[5005], fi[5005], vt[5005], nx[5005], mx[5005];   int a[100005];   double prob[5005];   double f[5005][5005 + 5];   void sx(int l, int r) {     if (l >= r) return;     int i = l, j = r;     int chot = vt[l + rand() % (r - l + 1)];     int chot2 = fi[chot];     chot = st[chot];     while (i <= j) {       while (st[vt[i]] < chot || (st[vt[i]] == chot && fi[vt[i]] > chot2)) i++;       while (st[vt[j]] > chot || (st[vt[j]] == chot && fi[vt[j]] < chot2)) j--;       if (i <= j) {         if (i < j) {           int tg = vt[i];           vt[i] = vt[j];           vt[j] = tg;         }         i++;         j--;       }     }     sx(i, r);     sx(l, j);   }   void duyet(int ii) {     int sz = dsc[ii].size();     mx[ii] = 0;     if (sz == 0) {       for (int i = st[ii]; i <= fi[ii]; i++)         if (mx[ii] < a[i]) mx[ii] = a[i];     } else {       for (int i = st[ii]; i < st[dsc[ii][0]]; i++)         if (mx[ii] < a[i]) mx[ii] = a[i];       for (int j = 0; j < sz - 1; j++) {         for (int i = fi[dsc[ii][j]] + 1; i < st[dsc[ii][j + 1]]; i++)           if (mx[ii] < a[i]) mx[ii] = a[i];       }       for (int i = fi[dsc[ii][sz - 1]] + 1; i <= fi[ii]; i++)         if (mx[ii] < a[i]) mx[ii] = a[i];     }     for (int i = 0; i < sz; i++) {       duyet(dsc[ii][i]);       if (mx[dsc[ii][i]] > mx[ii]) mx[ii] = mx[dsc[ii][i]];     }     if (sz == 0) {       f[ii][0] = 1 - prob[ii];       for (int j = 1; j < 5005; j++) f[ii][j] = 1.0;     } else {       double f1, f2;       for (int j = 0; j < 5005; j++) {         f1 = f2 = 1.0;         for (int i = 0; i < sz; i++) {           int tmp = mx[ii] - mx[dsc[ii][i]] + j;           if (tmp >= 5005) tmp = 5005 - 1;           f1 *= f[dsc[ii][i]][tmp];           tmp = mx[ii] - mx[dsc[ii][i]] + j - 1;           if (tmp >= 5005) tmp = 5005 - 1;           if (tmp < 0)             f2 = 0;           else             f2 *= f[dsc[ii][i]][tmp];         }         if (j > 0)           f[ii][j] = (1 - prob[ii]) * f1 + prob[ii] * f2;         else           f[ii][j] = (1 - prob[ii]) * f1;       }     }   }   int main() {     int n, q;     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= q; i++) {       scanf( %d%d%lf , &st[i], &fi[i], &prob[i]);       vt[i] = i;     }     srand(time(NULL));     sx(1, q);     q++;     st[0] = 1;     fi[0] = n;     prob[0] = 0;     vt[0] = 0;     nx[0] = 0;     int topNX = 0;     for (int i = 1; i <= n; i++) dsc[i].clear();     for (int i = 1; i < q; i++) {       while (fi[vt[nx[topNX]]] < fi[vt[i]]) topNX--;       dsc[vt[nx[topNX]]].push_back(vt[i]);       nx[++topNX] = i;     }     duyet(0);     double res = 0.0;     for (int j = 0; j < 5005; j++) {       double pp = f[0][j];       if (j > 0) pp -= f[0][j - 1];       res += pp * (mx[0] + j);     }     printf( %.10lf , res);     return 0;   }   