4821: [Sdoi2017]相关分析
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]相关分析的更多相关文章
- (WA)BZOJ 4821: [Sdoi2017]相关分析
二次联通门 : BZOJ 4821: [Sdoi2017]相关分析 2017.8.23 Updata 妈妈!!这道题卡我!!!就是不然我过!!!!! #include <cstdio> # ...
- ●BZOJ 4821 [Sdoi2017]相关分析
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=4821 题解: 线段树是真的恶心,(也许是我的方法麻烦了一些吧)首先那个式子可以做如下化简: ...
- bzoj 4821 [Sdoi2017]相关分析
题面 https://www.lydsy.com/JudgeOnline/problem.php?id=4821 题解 做法显然 就是维护一颗线段树 里面装4个东西 区间x的和 区间y的和 区间$x^ ...
- BZOJ.4821.[SDOI2017]相关分析(线段树)
BZOJ LOJ 洛谷 恶心的拆式子..然后就是要维护\(\sum x_i,\ \sum y_i,\ \sum x_iy_i,\ \sum x_i^2\). 操作三可以看成初始化一遍,然后同操作二. ...
- BZOJ 4821 [Sdoi2017]相关分析 ——线段树
打开题面,看到许多$\sum$ woc,好神啊,SDOI好强啊 然后展开之后,woc,SDOI好弱啊,怎么T3出个线段树裸题啊. 最后写代码的时候,woc,SDOI怎么出个这么码农的题啊,怎么调啊. ...
- BZOJ 4821: [Sdoi2017]相关分析 线段树 + 卡精
考试的时候切掉了,然而卡精 + 有一个地方忘开 $long long$,完美挂掉 $50$pts. 把式子化简一下,然后直接拿线段树来维护即可. Code: // luogu-judger-enabl ...
- BZOJ4817 SDOI2017 相关分析
4821: [Sdoi2017]相关分析 Time Limit: 10 Sec Memory Limit: 128 MBSec Special Judge Description Frank对天文 ...
- [Sdoi2017]相关分析 [线段树]
[Sdoi2017]相关分析 题意:沙茶线段树 md其实我考场上还剩一个多小时写了40分 其实当时写正解也可以吧1h也就写完了不过还要拍一下 正解代码比40分短2333 #include <io ...
- [题目] Luogu P3707 [SDOI2017]相关分析
参考资料:[Luogu 3707] SDOI2017 相关分析 P3707 [SDOI2017]相关分析 TFRAC FRAC DFRAC \(\tfrac{\sum}{1}\) \(\frac{\s ...
随机推荐
- [控件] AngleGradientView
AngleGradientView 效果 说明 1. 用源码产生带环形渐变色的view 2. 可以配合maskView一起使用 (上图中的右下角图片的效果) 源码 https://github.com ...
- swift中变量的几种类型
swift中变量的几种类型 swift中变量分为 optional,non-optional 以及 implicitly unwrapped optional 这几种类型 var nullablePr ...
- Eclipse validation
window->preferences->validation 可以取消部分文件的验证,取消build时验证,改为手动验证,提高效率.
- Hibernate事务、缓存和连接池
一.事务 1.数据库事务的概念 数据库事务是指由一个或多个SQL语句组成的工作单元,这个工作单元中的SQL语句相互依赖,如果有一个SQL语句执行失败,就必须撤销整个工作单元.在并发环境中,多个事务同时 ...
- 如何检查oracle的归档空间是否满了
如何检查oracle的归档空间是否满了 关于如何检查归档空间是否慢了,大多数人会去先检查放归档的目录的磁盘空间是否满了,通过该归档目录空余情况来判断归档空间是否满了,但我觉得这个方法不一定代表实际 ...
- Oracle学习(十一):PL/SQL
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/v123411739/article/details/30231659 1.知识点:能够对照以下的录屏 ...
- 1833. [ZJOI2010]数字计数【数位DP】
Description 给定两个正整数a和b,求在[a,b]中的所有整数中,每个数码(digit)各出现了多少次. Input 输入文件中仅包含一行两个整数a.b,含义如上所述. Output 输出文 ...
- Linux终端里的记录器
我们在调试程序的时候,免不了要去抓一些 log ,然后进行分析. 如果 log 量不是很大的话,那很简单,只需简单的复制粘贴就好. 但是如果做一些压力测试,产生大量 log ,而且系统内存又比较小(比 ...
- 有关linqtosql和EF的区别
LINQ to SQL和Entity Framework都是一种包含LINQ功能的对象关系映射技术.他们之间的本质区别在于EF对数据库架构和我们查询的类型实行了更好的解耦.使用EF,我们查询的对象不再 ...
- 【转】numpy.random.randn()与rand()的区别
转自: https://blog.csdn.net/u010758410/article/details/71799142 numpy中有一些常用的用来产生随机数的函数,randn()和rand()就 ...