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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
| #include <cstdio>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <cstring>
#define eps 1e-10
#define inf 1e10
using namespace std;
const int MAXN = 1100000;
int n,s;
double a[MAXN],b[MAXN],r[MAXN];
double dp[MAXN];
int last[MAXN];
double calx(int j){if(j == 0) return inf;return dp[j]*r[j] / (r[j]*a[j] + b[j]);}
double caly(int j){return dp[j] / (r[j]*a[j]+b[j]);}
double calc(int i,int j){return calx(j) * a[i] + caly(j) * b[i]; }
double cals(int i,int j){
if(j == 0) return -inf;
if(i == 0) return inf;
double _x = calx(i)-calx(j);
double _y = caly(i)-caly(j);
//if(fabs(_x) < eps) return _y>0?inf:-inf;
return _y/_x;
}
namespace Splay{
int p[MAXN<<2];double v[MAXN<<2];
int f[MAXN<<2],c[MAXN<<2][2],cnt;
int root;//v 向左连
int newnode(int point,double val = 0){
int x = ++cnt;
v[x] = val,p[x] = point;
c[x][0] = c[x][1] = 0;
return x;
}
void rotate(int x){
if(!x) return;
int y = f[x],z = f[y],t = c[y][1] == x,w = c[x][1-t];
if(z) c[z][c[z][1]==y] = x;
c[y][t] = w,c[x][1-t] = y;
if(w) f[w] = y;
f[x] = z;f[y] = x;
if(!f[x]) root = x;
}
void splay(int x,int tar = 0){
while(f[x]!=tar){
int y = f[x],z = f[y];
if(f[y] != tar){
(c[y][1]==x)^(c[z][1]==y)?rotate(x):rotate(y);
}rotate(x);
}
}
int find(int x,double _v){
if(!x) return 0;
if(_v > v[x])
return find(c[x][0],_v);
else{
int j = find(c[x][1],_v);
return j!=0?j:x;
}
}
int nxt(int x,int tmp){
if(!x) return 0; splay(x);
int r = c[x][tmp]; if(!r) return 0;
while(1){
if(c[r][1-tmp]) r = c[r][1-tmp];
else return r;
}
}
int insert(int x,int fa,int point){
if(!x){
int w = newnode(point);
if(fa == 0) root = w;
c[fa][calx(point) > calx(p[fa])] = w,f[w] = fa;
int _x = nxt(w,0),_y = nxt(w,1);
v[w] = cals(p[_x],p[w]);
if(_y) v[_y] = cals(p[w],p[_y]);
return w;
}
int tmp = calx(point) > calx(p[x]);
return insert(c[x][tmp],x,point);
}
void erase(int x){
int _x = nxt(x,0),_y = nxt(x,1);
if(!_x && !_y) root = 0;
else if(!_x || !_y){
int t = _x == 0?_y:_x,tmp = _x==0?0:1;
splay(t),c[t][tmp] = 0;
}
else{
splay(_x),splay(_y,_x);
c[_y][0] = 0;
}
if(_y) v[_y] = cals(p[_x],p[_y]);
}
void update(int i){
int w = insert(root,0,i);
int x,y;
x = nxt(w,0),y = nxt(w,1);
if(y && cals(p[x],p[y]) < v[y]){
erase(w);return;
}
x = nxt(w,1),y = nxt(x,1);
while(y!=0){
if(cals(i,p[x]) > cals(i,p[y])) break;
erase(x);
x = y;
y = nxt(x,1);
}
x = nxt(w,0),y = nxt(x,0);
while(y!=0){
if(cals(p[y],i) > cals(p[x],i)) break;
erase(x);
x = y;
y = nxt(x,0);
}
}
int query(int i){
return find(root,-a[i]/b[i]);
}
};
int main(){
scanf("%d %d",&n,&s);
for(int i = 1;i<=n;i++)
scanf("%lf %lf %lf",&a[i],&b[i],&r[i]);
dp[1] = s;
Splay::update(1);
for(int i = 2;i<=n;i++){
dp[i] = dp[i-1],last[i] = i;
int j = Splay::query(i);
if(calc(i,j) > dp[i])
last[i] = j,dp[i] = calc(i,j);
Splay::update(i);
}
printf("%.6lf\n",dp[n]);
return 0;
}
|