幻想月面战争

这是题解呢

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
#include<cstdio>
#define umax 100005

int 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;
}