这样的题解只能舔题解了,,,qaq
清橙资料里有。。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 #include <cmath> 6 #include <ctime> 7 #include <algorithm> 8 9 using namespace std; 10 11 struct Matrix 12 { 13 double a,b,c,d; 14 }; 15 16 struct node 17 { 18 double S0,S1; 19 Matrix S2; 20 }tree[2100000]; 21 22 double a[510000]; 23 24 void push_up(const int num,const int pos) 25 { 26 node &temp1=tree[num<<1],&temp2=tree[num<<1|1]; 27 tree[num].S0=temp1.S0+temp2.S0-a[pos]*a[pos+1]; 28 tree[num].S1=temp1.S1+temp2.S1; 29 Matrix t1=temp1.S2,t2=temp2.S2; 30 tree[num].S2=(Matrix){t1.a*t2.a,t1.a*t2.b+t1.b,t1.c*t2.a+t2.c,t1.c*t2.b+t1.d+t2.d}; 31 return ; 32 } 33 34 void Change(const int l,const int r,const int num,const int s,const node d) 35 { 36 if(l==r) 37 { 38 a[l]=d.S0; 39 tree[num]=d; 40 return ; 41 } 42 43 int mid=l+((r-l)>>1); 44 45 if(s<=mid)Change(l,mid,num<<1,s,d); 46 else Change(mid+1,r,num<<1|1,s,d); 47 48 push_up(num,mid); 49 return ; 50 } 51 52 node Calc(const node temp1,const node temp2,const int pos) 53 { 54 node A; 55 56 A.S0=temp1.S0+temp2.S0-a[pos]*a[pos+1]; 57 A.S1=temp1.S1+temp2.S1; 58 59 Matrix t1=temp1.S2,t2=temp2.S2; 60 A.S2=(Matrix){t1.a*t2.a,t1.a*t2.b+t1.b,t1.c*t2.a+t2.c,t1.c*t2.b+t1.d+t2.d}; 61 62 return A; 63 } 64 65 node Query(const int l,const int r,const int num,const int s,const int t) 66 { 67 if(s<=l && r<=t) 68 return tree[num]; 69 70 int mid=l+((r-l)>>1); 71 72 if(t<=mid)return Query(l,mid,num<<1,s,t); 73 if(s>mid) return Query(mid+1,r,num<<1|1,s,t); 74 return Calc(Query(l,mid,num<<1,s,t),Query(mid+1,r,num<<1|1,s,t),mid); 75 } 76 77 int main() 78 { 79 int n,m,i,op; 80 81 scanf("%d%d",&n,&m); 82 83 for(i=1;i<=n;++i) 84 scanf("%lf",&a[i]); 85 for(i=1;i<=n;++i) 86 Change(1,n,1,i,(node){a[i],a[i],(Matrix){a[i],a[i]*2,a[i],a[i]}}); 87 88 for(i=1;i<=m;++i) 89 { 90 scanf("%d",&op); 91 92 if(op==0) 93 { 94 int x,y; 95 scanf("%d%d",&x,&y); 96 97 node temp=Query(1,n,1,x,y); 98 printf("%.2f ",temp.S0+temp.S1+temp.S2.d); 99 } 100 101 if(op==1) 102 { 103 int x; 104 double y; 105 106 scanf("%d%lf",&x,&y); 107 Change(1,n,1,x,(node){y,y,(Matrix){y,y*2,y,y}}); 108 } 109 } 110 return 0; 111 }