后三个点wa,有哪位大佬来康康我哪里错了吗
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cctype>
#define ll long long
#define maxn 200007
#define lc o -> ch[0]
#define rc o -> ch[1]
#define SDOI2020 RP++
using namespace std;
const double eps = 1e-10;
int n,m;
double x[maxn],y[maxn],sumi[maxn],esumi[maxn],w1,w2;
inline int read()
{
register int x = 0;
int f = 1;
char ch = getchar();
while(!isdigit(ch))
{
if(ch == '-') f = -1;
ch = getchar();
}
while(isdigit(ch))
{
x = (x << 1) + (x << 3) + ch - 48;
ch = getchar();
}
return x * f;
}
struct node
{
node *ch[2];;
int l,r;
double sumx,sumy,esum,sumxy;
double ls,lt,flag,fs,ft;
node(int _x = 0,int _y = 0,int _esum = 0,int _sumxy = 0,int _l = 0,int _r = 0)
{
sumx = _x;
sumy = _y;
esum = _esum;
sumxy = _sumxy;
l = _l;
r = _r;
ls = 0;
lt = 0;
flag = 0;
}
}*root;
inline void push_up(node *o)
{
o -> sumx = lc -> sumx + rc -> sumx;
o -> sumy = lc -> sumy + rc -> sumy;
o -> esum = lc -> esum + rc -> esum;
o -> sumxy = lc -> sumxy + rc -> sumxy;
}
inline void build(node *&o,int l,int r)
{
if(o == NULL) o = new node(0,0,0,0,l,r);
o -> l = l;
o -> r = r;
if(l == r)
{
o -> sumx = x[l];
o -> sumy = y[l];
o -> esum = x[l] * x[l];
o -> sumxy = x[l] * y[l];
return ;
}
int mid = (l + r) >> 1;
build(lc,l,mid);
build(rc,mid + 1,r);
push_up(o);
}
inline void spread(node *o)
{
if(o -> flag)
{
if(lc)
{
lc -> fs = o -> fs;
lc -> ft = o -> ft;
lc -> flag = 1;
lc -> ls = lc -> lt = 0;
double s = o -> fs;
double t = o -> ft;
double len = lc -> r - lc -> l + 1;
lc -> esum = len * s * s + 2 * s * (sumi[lc -> r] - sumi[lc -> l - 1]) + esumi[lc -> r] - esumi[lc -> l - 1];
lc -> sumxy = len * s * t + (s + t) * (sumi[lc -> r] - sumi[lc -> l - 1]) + esumi[lc -> r] - esumi[lc -> l - 1];
lc -> sumx = len * s + (lc -> r + lc -> l) * len / 2;
lc -> sumy = len * t + (lc -> r + lc -> l) * len / 2;
}
if(rc)
{
rc -> fs = o -> fs;
rc -> ft = o -> ft;
rc -> flag = 1;
rc -> ls = rc -> lt = 0;
double s = o -> fs;
double t = o -> ft;
double len = rc -> r - rc -> l + 1;
rc -> esum = len * s * s + 2 * s * (sumi[rc -> r] - sumi[rc -> l - 1]) + esumi[rc -> r] - esumi[rc -> l - 1];
rc -> sumxy = len * s * t + (s + t) * (sumi[rc -> r] - sumi[rc -> l - 1]) + esumi[rc -> r] - esumi[rc -> l - 1];
rc -> sumx = len * s + (rc -> r + rc -> l) * len / 2;
rc -> sumy = len * t + (rc -> r + rc -> l) * len / 2;
}
o -> flag = 0;
}
if(o -> ls == 0 && o -> lt == 0) return ;
if(lc)
{
lc -> ls += o -> ls;
lc -> lt += o -> lt;
double len = lc -> r - lc -> l + 1;
double s = o -> ls;
double t = o -> lt;
lc -> esum += 2 * s * lc -> sumx + len * s * s;
lc -> sumxy += t * lc -> sumx + s * lc -> sumy + len * s * t;
lc -> sumx += len * s;
lc -> sumy += len * t;
}
if(rc)
{
rc -> ls += o -> ls;
rc -> lt += o -> lt;
double len = rc -> r - rc -> l + 1;
double s = o -> ls;
double t = o -> lt;
rc -> esum += 2 * s * rc -> sumx + len * s * s;
rc -> sumxy += t * rc -> sumx + s * rc -> sumy + len * s * t;
rc -> sumx += len * s;
rc -> sumy += len * t;
}
o -> ls = 0;
o -> lt = 0;
}
inline void add(node *o,int l,int r,double s,double t)
{
if(l <= o -> l && o -> r <= r)
{
double len = o -> r - o -> l + 1;
o -> esum += 2 * s * o -> sumx + len * s * s;
o -> sumxy += t * o -> sumx + s * o -> sumy + len * s * t;
o -> sumx += len * s;
o -> sumy += len * t;
o -> ls += s;
o -> lt += t;
return ;
}
spread(o);
int mid = (o -> l + o -> r) >> 1;
if(l <= mid) add(lc,l,r,s,t);
if(r > mid) add(rc,l,r,s,t);
push_up(o);
}
inline void update(node *o,int l,int r,double s,double t)
{
//cout<<o -> l << " " << o -> r <<endl;
if(l <= o -> l && o -> r <= r)
{
double len = o -> r - o -> l + 1;
o -> ls = 0;
o -> lt = 0;
o -> flag = 1;
o -> fs = s;
o -> ft = t;
o -> esum = len * s * s + 2 * s * (sumi[o -> r] - sumi[o -> l - 1]) + esumi[o -> r] - esumi[o -> l - 1];
o -> sumxy = len * s * t + (s + t) * (sumi[o -> r] - sumi[o -> l - 1]) + esumi[o -> r] - esumi[o -> l - 1];
o -> sumx = len * s + (o -> r + o -> l) * len / 2;
o -> sumy = len * t + (o -> r + o -> l) * len / 2;
return ;
}
int mid = (o -> l + o -> r) >> 1;
spread(o);
if(l <= mid) update(lc,l,r,s,t);
if(r > mid) update(rc,l,r,s,t);
push_up(o);
}
inline node query(node *o,int l,int r)
{
if(l <= o -> l && o -> r <= r)
{
return *o;
}
node ans(0,0,0,0);
node ans1(0,0,0,0);
int mid = (o -> l + o -> r) >> 1;
spread(o);
if(l <= mid) ans = query(lc,l,r);
if(r > mid) ans1 = query(rc,l,r);
ans.sumx += ans1.sumx;
ans.sumy += ans1.sumy;
ans.esum += ans1.esum;
ans.sumxy += ans1.sumxy;
return ans;
}
inline double calc(node a,int l,int r)
{
double len = (r - l + 1) * 1.0;
return double (a.sumxy - a.sumx * a.sumy / len) / (a.esum - a.sumx * a.sumx / len);
}
int main()
{
n = read();
m = read();
for(register int i = 1;i <= n;i++)
{
scanf("%lf",&x[i]);
sumi[i] = sumi[i - 1] + i;
esumi[i] = esumi[i - 1] + i * i;
}
for(register int i = 1;i <= n;i++)
{
scanf("%lf",&y[i]);
}
build(root,1,n);
for(register int i = 1;i <= m;i++)
{
int ops = read();
if(ops == 1)
{
int l = read();
int r = read();
printf("%.10lf\n",calc(query(root,l,r),l,r));
}
else if(ops == 2)
{
int l = read();
int r = read();
cin>>w1>>w2;
add(root,l,r,w1,w2);
}
else if(ops == 3)
{
int l = read();
int r = read();
cin>>w1>>w2;
update(root,l,r,w1,w2);
}
}
return 0;
}