4821: [Sdoi2017]相关分析

链接

分析:

  大力拆式子,化简,然后线段树。注意精度问题与爆longlong问题。

代码:

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
#define Root 1, n, 1
#define lc rt << 1
#define rc rt << 1 | 1
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
using namespace std;
typedef double DB; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ;
DB sx[N << ], sy[N << ], s[N << ], s2[N << ], tag[N << ], taga[N << ], tagb[N << ], X[N], Y[N];
DB sum[N], sum2[N];
DB Sx, Sy, S, S2;
int n; inline void pushup(int rt) {
sx[rt] = sx[lc] + sx[rc];
sy[rt] = sy[lc] + sy[rc];
s2[rt] = s2[lc] + s2[rc];
s[rt] = s[lc] + s[rc];
}
inline void col(int rt,int l,int r) {
sy[rt] = sx[rt] = sum[r] - sum[l - ];
s2[rt] = s[rt] = sum2[r] - sum2[l - ];
tag[rt] = ; taga[rt] = tagb[rt] = ;
}
inline void add(int rt,DB len,DB a,DB b) {
s[rt] += sx[rt] * b + sy[rt] * a + a * b * len;
s2[rt] += a * a * len + * a * sx[rt];
sx[rt] += a * len;
sy[rt] += b * len;
taga[rt] += a, tagb[rt] += b;
}
inline void pushdown(int rt,int l,int r) {
int mid = (l + r) >> ;
if (tag[rt]) {
col(lc, l, mid); col(rc, mid + , r);
tag[rt] = ;
}
if (taga[rt] || tagb[rt]) { // !!!
add(lc, mid - l + , taga[rt], tagb[rt]);
add(rc, r - mid, taga[rt], tagb[rt]);
taga[rt] = tagb[rt] = ;
}
}
void build(int l,int r,int rt) {
if (l == r) {
sx[rt] = X[l], sy[rt] = Y[l], s[rt] = X[l] * Y[l], s2[rt] = X[l] * X[l]; return ;
}
int mid = (l + r) >> ;
build(lson), build(rson);
pushup(rt);
}
void update(int l,int r,int rt,int L,int R,DB a,DB b) {
if (L <= l && r <= R) {
add(rt, r - l + , a, b); return ;
}
int mid = (l + r) >> ;
pushdown(rt, l, r);
if (L <= mid) update(lson, L, R, a, b);
if (R > mid) update(rson, L, R, a, b);
pushup(rt);
}
void Change(int l,int r,int rt,int L,int R) {
if (L <= l && r <= R) {
col(rt, l, r); return ;
}
int mid = (l + r) >> ;
pushdown(rt, l, r);
if (L <= mid) Change(lson, L, R);
if (R > mid) Change(rson, L, R);
pushup(rt);
}
void query(int l,int r,int rt,int L,int R) {
if (L <= l && r <= R) {
Sx += sx[rt], Sy += sy[rt], S += s[rt], S2 += s2[rt]; return ;
}
int mid = (l + r) >> ;
pushdown(rt, l, r);
if (L <= mid) query(lson, L, R);
if (R > mid) query(rson, L, R);
}
void Ask() {
int l = read(), r = read();
Sx = Sy = S = S2 = ;
query(Root, l, r);
double x = 1.0 * Sx / (r - l + ), y = 1.0 * Sy / (r - l + );
// double u = S - Sy * x - Sx * y + x * y * (r - l + 1);
// double d = S2 + x * x * (r - l + 1) - 2 * Sx * x;
double u = S - y * Sx, d = S2 - x * Sx;
printf("%.10lf\n", (double)(u / d));
}
void work1() {
int l = read(), r = read();
DB a = (DB)read(), b = (DB)read();
update(Root, l, r, a, b);
}
void work2() {
int l = read(), r = read();
DB a = (DB)read(), b = (DB)read();
Change(Root, l, r);
update(Root, l, r, a, b);
}
int main() {
n = read();int m = read();
for (int i = ; i <= n; ++i) {
sum[i] = sum[i - ] + 1.0 * i;
sum2[i] = sum2[i - ] + 1.0 * i * i; // 此处报int !!!
}
for (int i = ; i <= n; ++i) X[i] = (DB)read();
for (int i = ; i <= n; ++i) Y[i] = (DB)read();
build(Root);
while (m --) {
int opt = read();
if (opt == ) Ask();
else if (opt == ) work1();
else work2();
}
return ;
}

4821: [Sdoi2017]相关分析的更多相关文章

  1. (WA)BZOJ 4821: [Sdoi2017]相关分析

    二次联通门 : BZOJ 4821: [Sdoi2017]相关分析 2017.8.23 Updata 妈妈!!这道题卡我!!!就是不然我过!!!!! #include <cstdio> # ...

  2. ●BZOJ 4821 [Sdoi2017]相关分析

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=4821 题解: 线段树是真的恶心,(也许是我的方法麻烦了一些吧)首先那个式子可以做如下化简: ...

  3. bzoj 4821 [Sdoi2017]相关分析

    题面 https://www.lydsy.com/JudgeOnline/problem.php?id=4821 题解 做法显然 就是维护一颗线段树 里面装4个东西 区间x的和 区间y的和 区间$x^ ...

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

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

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

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

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

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

  7. BZOJ4817 SDOI2017 相关分析

    4821: [Sdoi2017]相关分析 Time Limit: 10 Sec  Memory Limit: 128 MBSec  Special Judge Description Frank对天文 ...

  8. [Sdoi2017]相关分析 [线段树]

    [Sdoi2017]相关分析 题意:沙茶线段树 md其实我考场上还剩一个多小时写了40分 其实当时写正解也可以吧1h也就写完了不过还要拍一下 正解代码比40分短2333 #include <io ...

  9. [题目] Luogu P3707 [SDOI2017]相关分析

    参考资料:[Luogu 3707] SDOI2017 相关分析 P3707 [SDOI2017]相关分析 TFRAC FRAC DFRAC \(\tfrac{\sum}{1}\) \(\frac{\s ...

随机推荐

  1. The operation names in the portType match the method names in the SEI or Web service implementation class.

    The Endpoint validation failed to validate due to the following errors: :: Invalid Endpoint Interfac ...

  2. C# 判断程序是否已经在运行

    方式1: /// <summary> /// 应用程序的主入口点. /// </summary> [STAThread] static void Main() { //获取欲启 ...

  3. 细说C#继承

    简介 继承(封装.多态)是面向对象编程三大特性之一,继承的思想就是摈弃代码的冗余,实现更好的重用性. 继承从字面上理解,无外乎让人想到某人继承某人的某些东西,一个给一个拿.这个语义在生活中,就像 家族 ...

  4. iOS系统声音列表

    iOS系统声音列表 效果 说明 1. 点击cell就能发出声音 2. 只需要给出声音编号,就可以,非常简单易用 源码 https://github.com/YouXianMing/iOS-Utilit ...

  5. Python入门-模块2(random模块、os模块)

    >>> random.randomrange(1,10) #返回1-10之间的一个随机数,不包括10 >>> random.randint(1,10) #返回1-1 ...

  6. 申请Let’s Encrypt永久免费SSL证书过程教程及常见问题

    配置证书https://easy.zhetao.com/   虽然目前Let’s Encrypt免费SSL证书默认是90天有效期,但是我们也可以到期自动续约,不影响我们的尝试和使用,为了考虑到文章的真 ...

  7. [EffectiveC++]item32:确定你的public继承模塑出is-a关系

  8. 快速搭建一个Express工程骨架

    下载express-generator 通过应用生成器,可以帮我们快速搭建项目需要的骨架.这就需要npm在全局下载express-generator(-g就是在全局安装) npm install ex ...

  9. 【原创】python web应用性能测试出现的问题以及使用的工具

    uwsgi参数设置问题 问题汇总 listen 参数设置过小导致并发上不去 解决办法 更改listen参数, 请先确认linux系统的上限(tcp_max_syn_backlog,somaxconn) ...

  10. spring中MessageSource的配置使用方法1[转]

    本文转载仅供自己学习收录,不做任何商业用途,如有需要请访问文章原地址:http://blog.csdn.net/qyf_5445/article/details/8124306 Spring定义了访问 ...