[Sdoi2017]相关分析

题意:沙茶线段树


md其实我考场上还剩一个多小时写了40分

其实当时写正解也可以吧1h也就写完了不过还要拍一下

正解代码比40分短2333

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
#define fir first
#define sec second
#define lc x<<1
#define rc x<<1|1
#define mid ((l+r)>>1)
#define lson lc, l, mid
#define rson rc, mid+1, r const int N=1e5+5, INF=1e9, M=1e5+5;
inline int read() {
char c=getchar(); int x=0, f=1;
while(c<'0' || c>'9') {if(c=='-')f=-1; c=getchar();}
while(c>='0' && c<='9') {x=x*10+c-'0'; c=getchar();}
return x*f;
} int n, Q, op, ql, qr;
double a[N], b[N], s, w; namespace seg {
struct meow{
double a, b, c, a2, ta, tb, sa, sb;
meow(): sa(-1), sb(-1) {}
meow(double a, double b, double c, double a2): a(a), b(b), c(c), a2(a2), ta(0), tb(0), sa(-1), sb(-1){}
} t[N<<2];
meow operator + (const meow &x, const meow &y) { return meow(x.a + y.a, x.b + y.b, x.c + y.c, x.a2 + y.a2); } inline double cal2(double n) {return n * (n+1) * (2*n + 1) / 6;}
inline void _set(int x, int l, int r, double s, double w) {
meow &now = t[x];
now.sa = s; now.sb = w;
now.ta = now.tb = 0; // clear
double len = r-l+1, val = (l+r) * len / 2;
now.a = len * s + val;
now.b = len * w + val;
double val2 = cal2(r) - cal2(l-1);
now.c = val2 + val * (s + w) + s * w * len;
now.a2 = val2 + val * (s + s) + s * s * len;
}
inline void _add(int x, int l, int r, double s, double w) {
meow &now = t[x];
now.ta += s; now.tb += w;
double len = r-l+1;
now.c += now.a * w + now.b * s + s * w * len;
now.a2 += now.a * (s + s) + s * s * len;
now.a += len * s;
now.b += len * w;
} inline void pushdn(int x, int l, int r) {
if(t[x].sa != -1 || t[x].sb != -1) {
_set(lson, t[x].sa, t[x].sb);
_set(rson, t[x].sa, t[x].sb);
t[x].sa = t[x].sb = -1;
}
if(t[x].ta || t[x].tb) {
_add(lson, t[x].ta, t[x].tb);
_add(rson, t[x].ta, t[x].tb);
t[x].ta = t[x].tb = 0;
}
} void build(int x, int l, int r) {
if(l == r) t[x] = meow(a[l], b[l], a[l] * b[l], a[l] * a[l]);
else {
build(lson); build(rson);
t[x] = t[lc] + t[rc];
}
} void add(int x, int l, int r) {
if(ql<=l && r<=qr) _add(x, l, r, s, w);
else {
pushdn(x, l, r);
if(ql <= mid) add(lson);
if(mid < qr ) add(rson);
t[x] = t[lc] + t[rc];
}
} void cha(int x, int l, int r) {
if(ql<=l && r<=qr) _set(x, l, r, s, w);
else {
pushdn(x, l, r);
if(ql <= mid) cha(lson);
if(mid < qr ) cha(rson);
t[x] = t[lc] + t[rc];
}
} meow que(int x, int l, int r) {
if(ql<=l && r<=qr) return t[x];
else {
pushdn(x, l, r);
if(qr <= mid) return que(lson);
else if(mid < ql ) return que(rson);
else return que(lson) + que(rson);
}
} void Quer() {
meow x = que(1, 1, n);
double len = qr-ql+1, ans1 = x.c - x.a * x.b / len, ans2 = x.a2 - x.a * x.a / len;
printf("%.10lf\n", ans1 / ans2);
}
}
int main() {
//freopen("in", "r", stdin);
freopen("relative.in", "r", stdin);
freopen("relative.out", "w", stdout);
n=read(); Q=read();
for(int i=1; i<=n; i++) a[i]=read();
for(int i=1; i<=n; i++) b[i]=read();
seg::build(1, 1, n); for(int i=1; i<=Q; i++) {
op=read(); ql=read(); qr=read();
if(op == 1) seg::Quer();
if(op == 2) s=read(), w=read(), seg::add(1, 1, n);
if(op == 3) s=read(), w=read(), seg::cha(1, 1, n);
}
}

[Sdoi2017]相关分析 [线段树]的更多相关文章

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

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

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

    打开题面,看到许多$\sum$ woc,好神啊,SDOI好强啊 然后展开之后,woc,SDOI好弱啊,怎么T3出个线段树裸题啊. 最后写代码的时候,woc,SDOI怎么出个这么码农的题啊,怎么调啊. ...

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

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

  4. BZOJ 4821: [Sdoi2017]相关分析 线段树 + 卡精

    考试的时候切掉了,然而卡精 + 有一个地方忘开 $long long$,完美挂掉 $50$pts. 把式子化简一下,然后直接拿线段树来维护即可. Code: // luogu-judger-enabl ...

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

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

  6. SDOI2017相关分析 线段树

    题目 https://loj.ac/problem/2005 思路 \[ \sum_{L}^{R}{(x_i-x)^{2}} \] \[ \sum_{L}^{R}{(x_i^2-2*x_i*x+x^{ ...

  7. 【BZOJ4821】【SDOI2017】相关分析 [线段树]

    相关分析 Time Limit: 10 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description Frank对天文学非常感兴趣,他经 ...

  8. luogu3707 相关分析 (线段树)

    把式子展开以后会发现,可以用线段树维护$x,y,x*y,x^2$分别的区间和 然后操作有区间加和区间修改 这个pushdown的时候,如果改和加的标记同时存在,那一定是先改再加,要不然加的标记已经被清 ...

  9. LOJ #2005. 「SDOI2017」相关分析 线段树维护回归直线方程

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

随机推荐

  1. Travelling(spfa+状态压缩dp)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3001 Travelling Time Limit: 6000/3000 MS (Java/Others ...

  2. 【Git】Git基础操作

    repository:版本库又名仓库,可以简单理解成一个目录,这个目录里面的所有文件都可以被Git管理起来,每个文件的修改.删除,Git都能跟踪,以便任何时刻都可以追踪历史,或者在将来某个时刻可以&q ...

  3. VS2008 如何将Release版本设置可以调试的DEBUG版本

    VS2008 如何将Release版本设置可以调试的DEBUG版本 只需设置三个部分: 项目->属性->C/C++->General->Debug Information Fo ...

  4. [OpenCV学习笔记1][OpenCV基本数据类型]

    CvPoint基于二维整形坐标轴的点typedef struct CvPoint{int x; /* X 坐标, 通常以 0 为基点 */int y; /* y 坐标,通常以 0 为基点 */}CvP ...

  5. Android开发——BroadcastReceiver广播的使用

    想要了解广播定义及相关原理的可以看下这一篇BroadcastReceiver史上最全面解析 简单地对广播进行分类吧,广播有两个角色,一个是广播发送者,另外一个是广播接收者 广播按照类型分为两种,一种是 ...

  6. Tp-link路由器怎么设置端口映射 内网端口映射听语音

    https://jingyan.baidu.com/article/ca00d56c710ef9e99eebcf85.html 只有一台能上网的电脑就可以自己免费搭建服务器,本经验简单介绍家用tp-l ...

  7. zTree中父节点禁用,子节点可以用

    参考学习网址:http://www.treejs.cn/v3/main.php#_zTreeInfo zTree中父节点禁用,子节点可以用 axios.get('/base/unit/unittree ...

  8. Java进阶篇(四)——Java异常处理

    程序中总是存在着各种问题,为了使在程序执行过程中能正常运行,使用Java提供的异常处理机制捕获可能发生的异常,对异常进行处理并使程序能正常运行.这就是Java的异常处理. 一.可捕获的异常 Java中 ...

  9. 配置shiro错误

    在web配置工程中配置shiro,如果启动Tomcat,报错:org.apache.shiro.web.config.WebIniSecurityManagerFactory.setDefaults ...

  10. vue.js中的各种问题记录(包括环境问题和学习笔记)

    一.this relative module was not found: 问题的意思是这个模块找不到了 解决方法: 1)查看你入口文件的路径是否写错: 2)查看360杀毒是否拦截了你的文件. 二.v ...