幻想月面战争 发表于 2018-09-10 这是题解呢 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192#include<cstdio>#define umax 100005int n,m;double opi[umax];struct node{ int l,r; node* ls,* rs; double v,mul; node(int l,int r,node* ls,node* rs): l(l),r(r),ls(ls),rs(rs),v(ls->v*rs->v),mul(1) {} node(int l,int r,node* ls,node* rs,double v): l(l),r(r),ls(ls),rs(rs),v(v),mul(1) {} void covermul(double k) { for(int i=l;i<=r;i++) v=v*k; mul=mul*k; } void pushup() { v=ls->v*rs->v; } void pushdown() { ls->covermul(mul); rs->covermul(mul); mul=1; } void update1(int l,int r,double k) { if(l > this->r||r < this->l) return; if(l <= this->l&&r >= this->r) covermul(k); else { pushdown(); ls->update1(l,r,k); rs->update1(l,r,k); pushup(); } return; } double query(int l,int r) { if(l > this->r||r < this->l) return 1.0; if(l <= this->l&&r >= this->r) return v; pushdown(); return ls->query(l,r)*rs->query(l,r); } static node *build(int l,int r) { if(l>r) return NULL; else if(l==r) { return new node(l,r,NULL,NULL,opi[l]); } else { int mid=(l+r)>>1; return new node(l,r,build(l,mid),build(mid+1,r)); } }}*root;int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%lf",&opi[i]); for(int i=1;i<=n;i++) opi[i]=1.0-opi[i]; root=node::build(1,n); int tmp,l,r; double k; while(m--) { scanf("%d",&tmp); if(tmp==1) { scanf("%d%d%lf",&l,&r,&k); root->update1(l,r,k); } else if(tmp==0) { scanf("%d%d",&l,&r); printf("%.6lf\n",root->query(l,r)); } } return 0;}