CodeForces 712E

线段树,区间并
定义
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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值