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. Entity Framework的几种初始化器

    Database.SetInitializer<TContext>(new NullDatabaseInitializer<TContext>()); Database.Set ...

  2. RAC性能分析 - gc buffer busy acquire 等待事件

    概述---------------------gc buffer busy是RAC数据库中常见的等待事件,11g开始gc buffer  busy分为gc buffer busy acquire和gc ...

  3. MySQL: OPTIMIZE TABLE: Table does not support optimize, doing recreate + analyze instead

    show create table history;-------------------------- CREATE TABLE `foo` (  `itemid` bigint(20) unsig ...

  4. 2. 跟踪标记 (Trace Flag) 3604, 3605 输出DBCC命令结果

    跟踪标记:3604 功能: 输出DBCC命令返回结果到查询窗口(通常是SSMS窗口),类似print命令的显示效果: 用途: 常用于获取DBCC IND, DBCC PAGE命令的输出结果,因为这2个 ...

  5. Ubuntu16.04安装redis和php的redis扩展

    安装redis服务 sudo apt-get install redis-server 装好之后默认就是自启动.后台运行的,无需过多设置,安装目录应该是  /etc/redis 启动 sudo ser ...

  6. 阿里云堡垒机密钥连接ECS服务器

    文:铁乐与猫 2017-6月中旬 堡垒机远程桌面windows系统就不用细说了 堡垒机远程ssh连接linux系统倒要说一下,毕竟是为安全一般只用通过密钥连接,而不使用密码的方式连接. 首先我们得在需 ...

  7. Spring Boot 以 war 方式部署

    Spring Boot 默认自带了一个嵌入式的 Tomcat 服务器,可以以jar方式运行,更为常见的情况是需要将 Spring Boot 应用打包成一个 war 包,部署到 Tomcat.Jerry ...

  8. centos6.2/6.3/6.4+nginx+mysql5.5+php5.3.14

    一.安装所需软件包yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype free ...

  9. BZOJ4517:[SDOI2016]排列计数(组合数学,错排公式)

    Description 求有多少种长度为 n 的序列 A,满足以下条件: 1 ~ n 这 n 个数在序列中各出现了一次 若第 i 个数 A[i] 的值为 i,则称 i 是稳定的.序列恰好有 m 个数是 ...

  10. Day5 JavaScript(三)事件、表单验证以及初识jQuery

    事件 1)鼠标事件 mousedown mouseup 2)键盘事件 a) keydown:键被按下 b) keyup:键抬起 c) keypress:按下可打印字符的键时. document.onk ...