[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. hdu_2604Queuing(快速幂矩阵)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2604 Queuing Time Limit: 10000/5000 MS (Java/Others)  ...

  2. c# excel 导入 与 导出(可直接用)

    c#操作excel方式很多 采用OleDB读取EXCEL文件: 引用的com组件:Microsoft.Office.Interop.Excel.dll   读取EXCEL文件 将EXCEL文件转化成C ...

  3. java通过smtp发送电子邮件

    package com.sm.modules.oa.web; import javax.mail.Session; import javax.mail.Transport; import javax. ...

  4. Spark算子--mapPartitions和mapPartitionsWithIndex

    mapPartitions--Transformation类算子 代码示例 result   mapPartitionsWithIndex--Transformation类算子 代码示例 result ...

  5. Micropython TPYBoard 智能温控小风扇资料分享

    南方都下大雪了,苦逼的北方还没下雪,天寒地冻,不过这几天办公室空调开太大了就想到做一个温控小风扇,简单模型出来了.等夏天一定做一个美观精致的小风扇送给女朋友(如果有的话QAQ)话不多说直接上干货.(跪 ...

  6. 使用vue框架运行npm run dev 时报错解决

    使用使用vue框架运行npm run dev 时报错 如下: 原因: localhost:8080 有可能其他软件占用了,导致其他问题的出现 我们可以动态修改地址 解决: 进入项目文件的config文 ...

  7. Harris角点检测原理分析

    看到一篇从数学意义上讲解Harris角点检测很透彻的文章,转载自:http://blog.csdn.net/newthinker_wei/article/details/45603583 主要参考了: ...

  8. 【开发技术】 B/S、C/S的区别

    c/s     客户端----服务器端             可以用譬如vb或vc等语言开发,比如最常用的oicq就是.   需要在客户端安装软件. b/s     浏览器端----服务器端     ...

  9. 关于Spring的69个面试题

    这篇文章总结了一些关于Spring框架的重要问题,这些问题都是你在面试或笔试过程中可能会被问到的.下次你再也不用担心你的面试了,Java Code Geeks这就帮你解答. 大多数你可能被问到的问题都 ...

  10. html静态页面乱码

    1.将文件保存为UTF-8 2.写入以下代码 <!-- 防止中文乱码 --><meta http-equiv="Content-Type" content=&qu ...