分析:

化简一下就行了,注意一下平方和公式的运用以及精度的误差。

代码:

 #include<bits/stdc++.h>
using namespace std; const int maxn = ; int n,m; int x[maxn],y[maxn]; struct node{
int lazx1,lazx2,lazy1,lazy2;
double multi,sumx,sumy,sqr;
}T[maxn<<]; long long ump(int l,int r){
return (1ll*r*(r+)*(*r+)-1ll*(l-)*l*(*l-))/;
} void fugai(int now,int tl,int tr,int s,int t){
T[now].lazx2 = T[now].lazy2 = ;
T[now].lazx1 = s; T[now].lazy1 = t;
T[now].sumx = 1ll*((s+tl)+(s+tr))*(tr-tl+)/;
T[now].sumy = 1ll*((t+tl)+(t+tr))*(tr-tl+)/;
T[now].sqr = 1ll*(tr-tl+)*s*s+1ll*s*(tl+tr)*(tr-tl+)+ump(tl,tr);
T[now].multi=1ll*(tr-tl+)*s*t+1ll*(s+t)*(tl+tr)*(tr-tl+)/+ump(tl,tr);
} void add(int now,int tl,int tr,int s,int t){
T[now].lazx2+=s;T[now].lazy2 += t;
T[now].multi+=1ll*s*T[now].sumy+1ll*t*T[now].sumx+1ll*s*t*(tr-tl+);
T[now].sqr +=1ll*s*s*(tr-tl+)+2ll*s*T[now].sumx;
T[now].sumx += 1ll*s*(tr-tl+); T[now].sumy += 1ll*t*(tr-tl+);
} void push_up(int now){
T[now].multi = T[now<<].multi+T[now<<|].multi;
T[now].sumx = T[now<<].sumx+T[now<<|].sumx;
T[now].sumy = T[now<<].sumy+T[now<<|].sumy;
T[now].sqr = T[now<<].sqr+T[now<<|].sqr;
} void push_down1(int now,int tl,int tr){
int mid = (tl+tr)/;
fugai(now<<,tl,mid,T[now].lazx1,T[now].lazy1);
fugai(now<<|,mid+,tr,T[now].lazx1,T[now].lazy1);
T[now].lazx1 = T[now].lazy1 = ;
} void push_down2(int now,int tl,int tr){
int mid = (tl+tr)/;
add(now<<,tl,mid,T[now].lazx2,T[now].lazy2);
add(now<<|,mid+,tr,T[now].lazx2,T[now].lazy2);
T[now].lazx2 = T[now].lazy2 = ;
} void read(){
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)scanf("%d",&x[i]);
for(int i=;i<=n;i++) scanf("%d",&y[i]);
} node merge(node ai,node bi){
return (node){,,,,ai.multi+bi.multi,ai.sumx+bi.sumx,ai.sumy+bi.sumy,ai.sqr+bi.sqr};
} void build_tree(int now,int l,int r){
if(l == r){
T[now].lazx1 = T[now].lazy1 = ;
T[now].multi = 1ll*x[l]*y[l];
T[now].sumx = x[l];T[now].sumy = y[l];
T[now].sqr = 1ll*x[l]*x[l];
}else{
int mid = (l+r)/;
build_tree(now<<,l,mid);
build_tree(now<<|,mid+,r);
T[now].lazx1 = T[now].lazy1 = ;
push_up(now);
}
} node Query(int now,int tl,int tr,int l,int r){
if(tl >= l && tr <= r){return T[now];}
if(tl > r || tr < l){return (node){,,,,,,,};}
if(T[now].lazx1<=maxn||T[now].lazy1<=maxn) push_down1(now,tl,tr);
if(T[now].lazx2||T[now].lazy2) push_down2(now,tl,tr);
int mid = (tl+tr)/;
node ans = merge(Query(now<<,tl,mid,l,r),Query(now<<|,mid+,tr,l,r));
push_up(now);
return ans;
} void Modify1(int now,int tl,int tr,int l,int r,int s,int t){
if(tl >= l && tr <= r){
add(now,tl,tr,s,t);
return;
}
if(tl > r || tr < l){return;}
if(T[now].lazx1<=maxn||T[now].lazy1<=maxn) push_down1(now,tl,tr);
if(T[now].lazx2||T[now].lazy2) push_down2(now,tl,tr);
int mid = (tl+tr)/;
Modify1(now<<,tl,mid,l,r,s,t);
Modify1(now<<|,mid+,tr,l,r,s,t);
push_up(now);
} void Modify2(int now,int tl,int tr,int l,int r,int s,int t){
if(tl >= l && tr <= r){
fugai(now,tl,tr,s,t);
return;
}
if(tl > r || tr < l){return;}
if(T[now].lazx1<=maxn||T[now].lazy1<=maxn) push_down1(now,tl,tr);
if(T[now].lazx2||T[now].lazy2) push_down2(now,tl,tr);
int mid = (tl+tr)/;
Modify2(now<<,tl,mid,l,r,s,t);
Modify2(now<<|,mid+,tr,l,r,s,t);
push_up(now);
} void work(){
build_tree(,,n);
for(int i=;i<=m;i++){
int cas; scanf("%d",&cas);
if(cas == ){
int l,r; scanf("%d%d",&l,&r);
node forw = Query(,,n,l,r);
double pjx = 1.0*forw.sumx/(r-l+),pjy = 1.0*forw.sumy/(r-l+);
double res=forw.multi+pjx*pjy*(r-l+)-pjx*forw.sumy-pjy*forw.sumx;
res /= 1.0*(forw.sqr+pjx*pjx*(r-l+)-2.0*pjx*forw.sumx);
printf("%.10lf\n",res);
}else{
if(cas == ){
int l,r,s,t; scanf("%d%d%d%d",&l,&r,&s,&t);
Modify1(,,n,l,r,s,t);
}else{
int l,r,s,t; scanf("%d%d%d%d",&l,&r,&s,&t);
Modify2(,,n,l,r,s,t);
}
}
}
} int main(){
read();
work();
return ;
}

洛谷3707 [SDOI2017] 相关分析 【线段树】的更多相关文章

  1. 洛谷P3707 [SDOI2017]相关分析(线段树)

    题目描述 Frank对天文学非常感兴趣,他经常用望远镜看星星,同时记录下它们的信息,比如亮度.颜色等等,进而估算出星星的距离,半径等等. Frank不仅喜欢观测,还喜欢分析观测到的数据.他经常分析两个 ...

  2. [Sdoi2017]相关分析 [线段树]

    [Sdoi2017]相关分析 题意:沙茶线段树 md其实我考场上还剩一个多小时写了40分 其实当时写正解也可以吧1h也就写完了不过还要拍一下 正解代码比40分短2333 #include <io ...

  3. 【BZOJ】1012: [JSOI2008]最大数maxnumber /【洛谷】1198(线段树)

    Description 现在请求你维护一个数列,要求提供以下两种操作:1. 查询操作.语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度.2. 插 ...

  4. 【BZOJ4821】[Sdoi2017]相关分析 线段树

    [BZOJ4821][Sdoi2017]相关分析 Description Frank对天文学非常感兴趣,他经常用望远镜看星星,同时记录下它们的信息,比如亮度.颜色等等,进而估算出星星的距离,半径等等. ...

  5. 洛谷题解P4314CPU监控--线段树

    题目链接 https://www.luogu.org/problemnew/show/P4314 https://www.lydsy.com/JudgeOnline/problem.php?id=30 ...

  6. 洛谷P3372/poj3468(线段树lazy_tag)(询问区间和,支持区间修改)

    洛谷P3372 //线段树 询问区间和,支持区间修改 #include <cstdio> using namespace std; struct treetype { int l,r; l ...

  7. 洛谷P4065 [JXOI2017]颜色(线段树)

    题意 题目链接 Sol 线段树板子题都做不出来,真是越来越菜了.. 根据题目描述,一个合法区间等价于在区间内的颜色没有在区间外出现过. 所以我们可以对于每个右端点,统计最长的左端点在哪里,刚开始以为这 ...

  8. 洛谷P5111 zhtobu3232的线段树

    题意:给定线段树,上面若干个节点坏了,求能表示出多少区间. 区间能被表示出当且仅当拆出来的log个节点都是好的. 解:每个区间在最浅的节点处计算答案. 对于每个节点维护从左边过来能有多少区间,从右边过 ...

  9. BZOJ.4821.[SDOI2017]相关分析(线段树)

    BZOJ LOJ 洛谷 恶心的拆式子..然后就是要维护\(\sum x_i,\ \sum y_i,\ \sum x_iy_i,\ \sum x_i^2\). 操作三可以看成初始化一遍,然后同操作二. ...

随机推荐

  1. form,ajax注册,logging日志使用

    一.form表单类型提交注册信息 二.ajax版本提交注册信息 <!DOCTYPE html> <html lang="en"> <head> ...

  2. Jenkins - SSH认证方式拉取Git代码

    1.本地生成密钥 [root@root ~] ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which ...

  3. 前端自动化 shell 脚本命令 与 shell-node 脚本命令 简单使用 之 es6 转译

    (背景: 先用 babel 转译 es6 再 用 browserify 打包 模块化文件,来解决浏览器不支持模块化 )(Browserify是一个让node模块可以用在浏览器中的神奇工具) 今天折腾了 ...

  4. Leetcode -- 394. Decode String

    Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where ...

  5. 008-我的博友不锈钢钥匙扣上的随身金属外壳可启动U盘-20190413

      008-我的博友不锈钢钥匙扣上的随身金属外壳可启动U盘-20190413

  6. Vue diff 算法

    一.虚拟 DOM (virtual dom) diff 算法首先要明确一个概念就是 diff 的对象是虚拟DOM(virtual dom),更新真实 DOM 是 diff 算法的结果. 注:virtu ...

  7. Linux下php安装redis扩展(redis已经安装)

     1. 下载需要的php操作redis的扩展包 (1).切换到 cd  /usr/local/src (2).   wget https://github.com/nicolasff/phpredis ...

  8. Open Live Writer安装教程

    配置步骤: 1.在菜单中选择"工具">"帐户",出现下面的画面: 2.点击"添加按钮",在出现的窗口中选择"其他日志服务&q ...

  9. awk+sed编程

  10. 访问修饰符 public private protected default