[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做相关分析比较简单,主要是区别如何使用这些相关系数,如果不想定量的分析相关性的话,直接观察散点图也可以. 相关系数有一些需要注 ...
随机推荐
- 作为小白该如何抉择python编辑器?
刚开始接触编程,有一个好的编辑器上手,那学习起来肯定是事半功倍的!本篇就给大家介绍适合零基础小白学习Python的四种编辑器,希望大家受用! 1.Sublime Text: 这是一个轻量级的代码编辑器 ...
- kubernetes kubeadm安装v1.14
1.我们这里准备两台Centos7的主机用于安装,后续节点可以根究需要添加即可:master node01两台都得改:cat /etc/hosts192.168.71.134 master192.16 ...
- MySQL 索引的优化
一.MySQL如何使用索引(index) 1.1 索引概述 索引用于快速查找具有特定列值的行. 如果不使用索引,MySQL必须从表的第一行开始,然后扫描整个表来寻找符合条件的行.这种情况下,表越大,扫 ...
- ItemsControl使用1
<ItemsControl ItemsSource="{Binding DataItemsSource}"> //绑定一个List <ItemsControl.I ...
- bootstrap-table的简单使用
先上效果图: 第一步:引用bootstrap-table的样式和js. @Styles.Render("~/assets/css/bootstrap.css") @Styles.R ...
- footer始终在页面最底部的方法(问题待检验)
一.css方法 <style type="text/css"> html,body{ height: 100%; } body{ display: flex; flex ...
- win10环境安装配置Nginx
前言: 参考 https://blog.csdn.net/kisscatforever/article/details/73129270 Nginx的应用场景 1. http服务器.Ngin ...
- JavaSpring【五、AOP基础】
概念: AOP--面向切面编程,通过预编译/动态代理实现程序功能的统一维护 主要功能是:日志.性能统计.安全控制.事务处理.异常处理 实现方式 预编译--AspectJ 动态代理--SpringAOP ...
- 前端基础(七):Toastr(弹出框)
Toastr 简介 jquery toastr 一款轻量级的通知提示框插件. 网页开发中经常会用到提示框,自带的alert样式无法调整,用户体验差. 所以一般通过自定义提示框来实现弹窗提示信息,而jq ...
- Linux基础知识之文件的权限(一)
Linux基础知识之文件权限(一) Linux优点之一就是它拥有多用户多任务的环境,在提供文件共享的同时也能保证用户文件的安全性.所以,设置文件的权限管理变得尤为重要. 权限讲解 [der@Der ~ ...