分析:

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

代码:

 #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. 两篇 Spring 总结(一)

    Spring4 概述以及 HelloWorld 概述 Spring 是一个 IOC(DI) 和 AOP 容器框架. 轻量级,Spring 是非侵入的,即使用的时候不需要实现任何接口或继承任何父类 面向 ...

  2. 关于eclipse tomcat 无法启动(8080,8005,8009端口被占用)的解决方法,附 eclipse tomcat 与 tomcat 并存方式

    eclipse 在编译运行时 新建的tomcat连接始终为stopped状态,描述为8080,8005,8009端口被占用. 这是因为在装完tomcat后,tomcat服务已启动,而eclipse仅仅 ...

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

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

  4. 通过 sass-resources-loader 全局注册 Sass/Less 变量

    使用webpack引入sass/less全局变量 sass或者less都提供变量设置,在需求切换主题的项目中使用less或者sass变量,只要修改变量值,编译后所有用到该变量的样式都会被修改为你想要的 ...

  5. hibernate异常找不到get方法org.hibernate.PropertyNotFoundException: Could not find a getter for did in class com.javakc.hibernate.manytomany.entity.CourseEntity

    属性的get方法没找到,可能是CourseEntity类中对应属性没有get方法,如果有就看CourseEntity.hbm.xml属性名称,应该是写错了不和CourseEntity类中属性名相同,修 ...

  6. es6在网页中模块引入的方法

    前言: 以前,当然包括现在的大部分js引入,我们都是利用<script></script>这种全局的方式进行引入,当然这种弊端还是用的,比如这样直接利用script引入的话,会 ...

  7. Navicat还原出现Finished - Stopped before completion的问题

    查看数据库中最大的单个文件容量 SHOW VARIABLES LIKE '%max_allowed_packet%';   设置最大单个文件容量为10M,单次有效(新建查询---运行) SET GLO ...

  8. 解决ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

    解决办法:

  9. Cookie-parser

    let express = require('express'); let app =new express(); // 引入cookie-parser; let cookieParser = req ...

  10. CIFS 与 SMB 有什么区别?

    CIFS 与 SMB 有什么区别? https://www.getnas.com/2018/11/30/cifs-vs-smb/ 网络协议 一知半解 学习一下挺好的.. 记得 win2019 已经废弃 ...