线段树,区间并
定义
a:从区间左端出发,在不出左端的情况下,走出右端
b:从区间右端出发,在不出左端的情况下,走出右端
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int N=1e5+100;
#define ll o<<1
#define rr o<<1|1
#define mid (l+r)/2
double aa[N];
double ss[N<<2],tt[N<<2];
double get1(double a,double b,double a1,double b1){
return a*a1/(1-(1-a1)*b);
}
double get2(double a,double b,double a1,double b1){
return b1+(1-b1)*a1*b/(1-(1-a1)*b);
}
void up(int o){
ss[o]=get1(ss[ll],tt[ll],ss[rr],tt[rr]);
tt[o]=get2(ss[ll],tt[ll],ss[rr],tt[rr]);
}
void build(int l,int r,int o){
if(l==r){
ss[o]=tt[o]=aa[l];
return ;
}
build(l,mid,ll);
build(mid+1,r,rr);
up(o);
}
void update(int l,int r,int o,int x,double p){
if(l==r){
ss[o]=tt[o]=p;
return ;
}
if(x<=mid)update(l,mid,ll,x,p);
else update(mid+1,r,rr,x,p);
up(o);
}
int L,R;double V1,V2;int cnt;
void query(int l,int r,int o){
if(L<=l&&r<=R){
if(cnt){
double t1,t2;
t1=get1(V1,V2,ss[o],tt[o]);
t2=get2(V1,V2,ss[o],tt[o]);
V1=t1,V2=t2;
}
else {
V1=ss[o],V2=tt[o];
}
cnt++;
return ;
}
if(L<=mid)query(l,mid,ll);
if(R>mid)query(mid+1,r,rr);
}
int main(){
#ifdef DouBi
freopen("in.cpp","r",stdin);
#endif // DouBi
int n,q;
while(scanf("%d%d",&n,&q)!=EOF){
for(int i=0;i<n;i++){
double a,b;scanf("%lf%lf",&a,&b);
aa[i]=a/b;
}
build(0,n-1,1);
while(q--){
int op;scanf("%d",&op);
if(op==1){
int a;double b,c;
scanf("%d%lf%lf",&a,&b,&c);a--;
update(0,n-1,1,a,b/c);
}
else {
int l,r;scanf("%d%d",&l,&r);l--,r--;
L=l,R=r;cnt=0;
query(0,n-1,1);
printf("%.10lf\n",V1);
}
}
}
return 0;
}