[Luogu] 相关分析
不想调了
#include <bits/stdc++.h> const int N = 1e5 + ; #define LL long long
#define gc getchar() int fjs;
struct Node {
LL xy, x, y, x_2, lenst, lens, lent, lentt;
LL S_2, T_2/*用于 2 操作*/, S_1, T_1/*用于 3 操作*/;
bool flag1/*用于 2 操作*/, flag2/*用于 3 操作*/;
int size;
int l, r;
};
Node T[N << ];
int impx[N], impy[N]; Node operator + (const Node &a, const Node &b) {
Node ret;
ret.x = a.x + b.x;
ret.y = a.y + b.y;
ret.xy = a.xy + b.xy;
ret.x_2 = a.x_2 + b.x_2;
ret.size = a.size + b.size;
return ret;
} int n, Ty, Len; inline LL read() {
LL x = , f = ; char c = gc;
while(c < '' || c > '') {if(c == '-') f = -; c = gc;}
while(c >= '' && c <= '') x = x * + c - '', c = gc;
return x * f;
} #define lson jd << 1
#define rson jd << 1 | 1 void Build_tree(int l, int r, int jd) {
T[jd].size = (r - l + ); T[jd].l = l; T[jd].r = r;
if(l == r) {
int x_ = impx[l], y_ = impy[l];
T[jd].x = x_;
T[jd].y = y_;
T[jd].xy = x_ * y_;
T[jd].x_2 = x_ * x_;
return ;
}
int mid = (l + r) >> ;
Build_tree(l, mid, lson);
Build_tree(mid + , r, rson);
T[jd] = T[lson] + T[rson];
} void Clear_1(int jd) {
T[jd].flag1 = T[jd].lenst = T[jd].lens = T[jd].lent = T[jd].lentt = ;
T[jd].S_1 = T[jd].T_1 = ;
} void Clear_2(int jd) {
T[jd].flag2 = ;
T[jd].S_2 = T[jd].T_2 = ;
} void Down_1(int jd) {
T[lson].flag1 = T[rson].flag1 = ++ fjs;
T[lson].S_1 += T[jd].S_1;
T[rson].S_1 += T[jd].S_1;
T[lson].T_1 += T[jd].T_1;
T[rson].T_1 += T[jd].T_1;
T[lson].lenst += T[jd].lenst;
T[rson].lenst += T[jd].lenst;
T[lson].lens += T[jd].lens;
T[rson].lens += T[jd].lens;
T[lson].lent += T[jd].lent;
T[rson].lent += T[jd].lent;
T[lson].lentt += T[jd].lentt;
T[rson].lentt += T[jd].lentt;
int s = T[jd].S_1, t = T[jd].T_1;
T[lson].xy += (t * T[lson].x + s * T[lson].y + T[jd].lenst);
T[lson].x_2 += ( * t * T[lson].x + T[jd].lentt);
T[lson].x += T[jd].lens;
T[lson].y += T[jd].lent;
T[rson].xy += (t * T[rson].x + s * T[rson].y + T[jd].lenst);
T[rson].x_2 += ( * t * T[rson].x + T[jd].lentt);
T[rson].x += T[jd].lens;
T[rson].y += T[jd].lent;
Clear_1(jd);
} void Work_1(int, int, int, int, int, int, int); void Down_2(int jd) {
T[lson].flag2 = T[rson].flag2 = ++ fjs;
T[lson].S_2 = T[rson].S_2 = T[jd].S_2;
T[lson].T_2 = T[rson].T_2 = T[jd].T_2;
int l, r;
l = T[lson].l, r = T[lson].r;
T[lson].xy = T[lson].x_2 = (r * (r + ) * ( * r + ) / ) - (l * (l - ) * ( * l - )) / ;
T[lson].x = T[lson].y = (l + r) / * (r - l + );
Work_1(, n, , l, r, T[jd].S_2, T[jd].T_2);
l = T[rson].l, r = T[rson].r;
T[rson].xy = T[rson].x_2 = (r * (r + ) * ( * r + ) / ) - (l * (l - ) * ( * l - )) / ;
T[rson].x = T[rson].y = (l + r) / * (r - l + );
Work_1(, n, , l, r, T[jd].S_2, T[jd].T_2);
Clear_2(jd);
} void Work_1(int l, int r, int jd, int x, int y, int s, int t) {
if(x <= l && r <= y) {
T[jd].flag1 = ++ fjs;
T[jd].S_1 = s;
T[jd].T_1 = s;
T[jd].xy += (t * T[jd].x + s * T[jd].y + Len * s * t);
T[jd].x_2 += ( * t * T[jd].x + Len * t * t);
T[jd].x += Len * s;
T[jd].y += Len * t;
T[jd].lenst += Len * s * t;
T[jd].lens += Len * s;
T[jd].lent += Len * t;
T[jd].lentt += Len * t * t;
return ;
}
if(T[jd].flag2 > T[jd].flag1) Down_1(jd), Down_2(jd);
else Down_2(jd), Down_1(jd);
int mid = (l + r) >> ;
if(x <= mid) Work_1(l, mid, lson, x, y, s, t);
if(y > mid) Work_1(mid + , r, rson, x, y, s, t);
T[jd] = T[lson] + T[rson];
} void Work_2(int l, int r, int jd, int x, int y, int s, int t) {
if(x <= l && r <= y) {
T[jd].flag2 = ++ fjs;
T[jd].S_2 = s;
T[jd].T_2 = t;
T[jd].xy = T[jd].x_2 = (r * (r + ) * ( * r + )) / - (l * (l - ) * ( * l - )) / ;
T[jd].x = T[jd].y = (l + r) / * (r - l + );
Work_1(, n, , l, r, s, t);
return ;
}
if(T[jd].flag2 > T[jd].flag1) Down_1(jd), Down_2(jd);
else Down_2(jd), Down_1(jd);
int mid = (l + r) >> ;
if(x <= mid) Work_2(l, mid, lson, x, y, s, t);
if(y > mid) Work_2(mid + , r, rson, x, y, s, t);
T[jd] = T[lson] + T[rson];
} int Sec_A_xy(int l, int r, int jd, int x, int y) {
if(x <= l && r <= y) return T[jd].xy;
if(T[jd].flag2 > T[jd].flag1) Down_1(jd), Down_2(jd);
else Down_2(jd), Down_1(jd);
int mid = (l + r) >> ;
if(y <= mid) return Sec_A_xy(l, mid, lson, x, y);
else if(x > mid) return Sec_A_xy(mid + , r, rson, x, y);
else return Sec_A_xy(l, mid, lson, x, y) + Sec_A_xy(mid + , r, rson, x, y);
} int Sec_A_x(int l, int r, int jd, int x, int y) {
if(x <= l && r <= y) return T[jd].x;
if(T[jd].flag2 > T[jd].flag1) Down_1(jd), Down_2(jd);
else Down_2(jd), Down_1(jd);
int mid = (l + r) >> ;
if(y <= mid) return Sec_A_x(l, mid, lson, x, y);
else if(x > mid) return Sec_A_x(mid + , r, rson, x, y);
else return Sec_A_x(l, mid, lson, x, y) + Sec_A_x(mid + , r, rson, x, y);
} int Sec_A_y(int l, int r, int jd, int x, int y) {
if(x <= l && r <= y) return T[jd].y;
if(T[jd].flag2 > T[jd].flag1) Down_1(jd), Down_2(jd);
else Down_2(jd), Down_1(jd);
int mid = (l + r) >> ;
if(y <= mid) return Sec_A_y(l, mid, lson, x, y);
else if(x > mid) return Sec_A_y(mid + , r, rson, x, y);
else return Sec_A_y(l, mid, lson, x, y) + Sec_A_y(mid + , r, rson, x, y);
} int Sec_A_x_2(int l, int r, int jd, int x, int y) {
if(x <= l && r <= y) return T[jd].x_2;
if(T[jd].flag2 > T[jd].flag1) Down_1(jd), Down_2(jd);
else Down_2(jd), Down_1(jd);
int mid = (l + r) >> ;
if(y <= mid) return Sec_A_x_2(l, mid, lson, x, y);
else if(x > mid) return Sec_A_x_2(mid + , r, rson, x, y);
else return Sec_A_x_2(l, mid, lson, x, y) + Sec_A_x_2(mid + , r, rson, x, y);
} int main() {
freopen("gg.in", "r", stdin);
n = read(); Ty = read();
for(int i = ; i <= n; i ++) impx[i] = read();
for(int i = ; i <= n; i ++) impy[i] = read();
Build_tree(, n, );
for(; Ty; Ty --) {
int opt = read(), l = read(), r = read(); Len = (r - l + );
if(opt == ) {
double a = Sec_A_xy(, n, , l, r) * 1.0;
double b = Sec_A_x(, n, , l, r) * 1.0;
double c = Sec_A_y(, n, , l, r) * 1.0;
double d = Sec_A_x_2(, n, , l, r) * 1.0;
double Ans = (a - b * c / (double)Len) / (double)(1.0 * d - 1.0 * b * b / (double)Len);
printf("%.10lf\n", Ans);
continue ;
}
int s = read(), t = read();
if(opt == ) Work_1(, n, , l, r, s, t);
else if(opt == ) Work_2(, n, , l, r, s, t);
}
return ;
}
[Luogu] 相关分析的更多相关文章
- [题目] Luogu P3707 [SDOI2017]相关分析
参考资料:[Luogu 3707] SDOI2017 相关分析 P3707 [SDOI2017]相关分析 TFRAC FRAC DFRAC \(\tfrac{\sum}{1}\) \(\frac{\s ...
- [Luogu 3707] SDOI2017 相关分析
[Luogu 3707] SDOI2017 相关分析 前言 Capella 和 Frank 一样爱好天文学. 她常在冬季的夜晚,若有所思地望着东北方上空的五边形中,最为耀眼的一个顶点. 那一抹金黄曾带 ...
- luogu P3707 [SDOI2017]相关分析
传送门 对于题目要求的东西,考虑拆开懒得拆了 ,可以发现有\(\sum x\sum y\sum x^2\sum xy\)四个变量影响最终结果,考虑维护这些值 下面记\(l,r\)为区间两端点 首先是区 ...
- 多视图学习利器----CCA(典型相关分析)及MATLAB实现
Hello,我是你们人见人爱花见花开的小花.又和大家见面了,今天我们来聊一聊多视图学习利器------CCA. 一 典型相关分析的基本思想 当我们研究两个变量x和y之间的相关关系的时候,相关系数(相关 ...
- SPSS数据分析—基于最优尺度变换的典型相关分析
传统的典型相关分析只能考虑变量之间的线性相关情况,且必须为连续变量,而我们依然可以使用最优尺度变换来拓展其应用范围,使其可以分析非线性相关.数据为分类数据等情况,并且不再仅限于两个变量间的分析, 虽然 ...
- SPSS数据分析—典型相关分析
我们已经知道,两个随机变量间的相关关系可以用简单相关系数表示,一个随机变量和多个随机变量的相关关系可以用复相关系数表示,而如果需要研究多个随机变量和多个随机变量间的相关关系,则需要使用典型相关分析. ...
- Luogu 魔法学院杯-第二弹(萌新的第一法blog)
虽然有点久远 还是放一下吧. 传送门:https://www.luogu.org/contest/show?tid=754 第一题 沉迷游戏,伤感情 #include <queue> ...
- luogu p1268 树的重量——构造,真正考验编程能力
题目链接:http://www.luogu.org/problem/show?pid=1268#sub -------- 这道题费了我不少心思= =其实思路和标称毫无差别,但是由于不习惯ACM风格的题 ...
- SPSS数据分析—相关分析
相关系数是衡量变量之间相关程度的度量,也是很多分析的中的当中环节,SPSS做相关分析比较简单,主要是区别如何使用这些相关系数,如果不想定量的分析相关性的话,直接观察散点图也可以. 相关系数有一些需要注 ...
随机推荐
- k8s-jenkins pipeline部署
- RSA加密,以及证书加密
简单的加密:https://blog.csdn.net/qq_32523587/article/details/79092364 生成证书:https://blog.csdn.net/u0121916 ...
- Unity上线google商店 用IL2Cpp打包64位版本和Android APP Bundle优化 及产生的bug
ios刚上线,这边着手改成android版本,我开始使用的是unity2017.4.1版本 上传谷歌商店是出现这两个警告: 要支持64位,但是在2017版本上没有找到64位的打包选项,猜测应该是版本的 ...
- dev gridview 视图层级
表格对象继承的关系
- django管理系统代码优化-分组(二)
django管理系统代码优化-分组(二) 后续进行代码更新,优化 一优化的内容 优化前代码:https://www.cnblogs.com/pythonywy/p/11345626.html 路由进行 ...
- [转载]PyTorch上的contiguous
[转载]PyTorch上的contiguous 来源:https://zhuanlan.zhihu.com/p/64551412 这篇文章写的非常好,我这里就不复制粘贴了,有兴趣的同学可以去看原文,我 ...
- gogs 搭建
sudo apt-get install nginx sudo apt-get install git sudo apt-get install mysql-server mysql -u root ...
- js面向对象的几种方式
对象的字面量 var obj={}:创建实例对象 var obj=new Object();构造函数模式 function fn(){}, new fn();工厂模式:用一个函数,通过传递参数返回对象 ...
- requests模块高级操作之cookie
一.cookie 存储在客户端的键值对,可以让服务端记录客户端相关状态. 如何处理cookie? 手动处理: 将抓包工具中的请求头信息中的cookie键值拷贝到header中 自动处理:session ...
- asp.net 简单的身份验证
1 通常我们希望已经通过身份验证的才能够登录到网站的后台管理界面,对于asp.net 介绍一种简单的身份验证方式 首先在webconfig文件中添加如下的代码 <!--身份验证--> &l ...