(WA)BZOJ 4821: [Sdoi2017]相关分析
二次联通门 : BZOJ 4821: [Sdoi2017]相关分析
2017.8.23 Updata
妈妈!!这道题卡我!!!就是不然我过!!!!!
#include <cstdio>
#include <iostream> const int BUF = ;
char Buf[BUF], *buf = Buf; inline void read (int &now)
{
bool temp = false;
for (now = ; !isdigit (*buf); ++ buf)
if (*buf == '-') temp = true;
for (; isdigit (*buf); now = now * + *buf - '', ++ buf);
if (temp) now = -now;
} #define Max 100050
double _x[Max], _y[Max];
double i2[Max], _i[Max]; struct S_D
{
S_D *Left, *Right;
double x, x2, y, xy, ss, st, ts, tt;
int l, r, Mid;
bool tag; S_D (int _l, int _r)
{
x = x2 = ss = st = ts = tt = y = xy = ;
Left = Right = NULL;
l = _l, r = _r, Mid = l + r >> ;
tag = false;
} inline void Up ()
{
x = Left->x + Right->x, xy = Left->xy + Right->xy;
y = Left->y + Right->y;
x2 = Left->x2 + Right->x2;
} inline void Down ()
{
S_D *L = Left, *R = Right; double ls = L->r - L->l + , rs = R->r - R->l + ;
if (tag)
{
L->x = ts * ls + _i[L->r] - _i[L->l - ];
L->y = tt * ls + _i[L->r] - _i[L->l - ];
L->xy = ts * tt * ls + (_i[L->r] - _i[L->l - ]) * (ts + tt) + i2[L->r] - i2[L->l - ];
L->x2 = ts * ts * ls + (_i[L->r] - _i[L->l - ]) * ts * 2.0 + i2[L->r] - i2[L->l - ]; R->x = ts * rs + _i[R->r] - _i[R->l - ];
R->y = tt * rs + _i[R->r] - _i[R->l - ];
R->xy = ts * tt * rs + (_i[R->r] - _i[R->l - ]) * (ts + tt) + i2[R->r] - i2[R->l - ];
R->x2 = ts * ts * rs + (_i[R->r] - _i[R->l - ]) * ts * 2.0 + i2[R->r] - i2[R->l - ];
L->ts = R->ts = ts, L->tt = R->tt = tt;
L->ss = R->st = L->st = R->ss = ;
tt = ts = , tag = false;
L->tag = R->tag = true;
}
if (ss || st)
{
L->xy += st * L->x + ss * L->y + ss * st * ls;
L->x2 += ss * L->x + ss * L->x + ss * ss * ls;
R->xy += st * R->x + ss * R->y + ss * st * rs;
R->x2 += ss * R->x + ss * R->x + ss * ss * rs;
L->x += ss * ls, R->x += ss * rs;
L->y += st * ls, L->y += st * rs;
L->ss += ss, R->ss += ss;
L->st += st, R->st += st;
ss = st = ;
}
}
}; struct D
{
double x, y, x2, xy;
D () : x (), y (), x2 (), xy () {}
D (double a, double b, double c, double d) : x (a), y (b), x2 (c), xy (d) {}
}; #define DE printf ("%lf %lf %lf %lf\n", now->x, now->y, now->x2, now->xy);
class Segment_Tree
{
private : S_D *Root; void Build (S_D *&now, int l, int r)
{
now = new S_D (l, r);
if (l == r)
{
now->x = (double)_x[l], now->y = (double)_y[r];
now->x2 = now->x * now->x;
now->xy = now->x * now->y;
return ;
}
Build (now->Left, l, now->Mid);
Build (now->Right, now->Mid + , r);
now->Up ();
} void Change_1 (S_D *&now, int l, int r, double s, double t)
{
if (l <= now->l && now->r <= r)
{
double L = (now->r - now->l + );
now->xy += t * now->x + s * now->y + s * t * L;
now->x2 += s * now->x + s * now->x + s * s * L;
now->x += s * L, now->y += t * L;
now->ss += s, now->st += t;
return ;
}
now->Down ();
if (l <= now->Mid) Change_1 (now->Left, l, r, s, t);
if (r > now->Mid) Change_1 (now->Right, l, r, s, t);
now->Up ();
} void Change_2 (S_D *&now, int l, int r, double s, double t)
{
if (l <= now->l && now->r <= r)
{
double L = (now->r - now->l + );
now->tag = true;
now->ss = now->st = , now->ts = s, now->tt = t;
now->x = L * s + _i[now->r] - _i[now->l - ];
now->y = L * t + _i[now->r] - _i[now->l - ];
now->xy = L * s * t + (s + t) * (_i[now->r] - _i[now->l - ]) + i2[now->r] - i2[now->l - ];
now->x2 = L * s * s + * s * (_i[now->r] - _i[now->l - ]) + i2[now->r] - i2[now->l - ];
return ;
}
now->Down ();
if (l <= now->Mid) Change_2 (now->Left, l, r, s, t);
if (r > now->Mid) Change_2 (now->Right, l, r, s, t);
now->Up ();
} D Query (S_D *&now, int l, int r)
{
if (l <= now->l && now->r <= r)
return D (now->x, now->y, now->x2, now->xy);
now->Down ();
D A, B;
if (l <= now->Mid) A = Query (now->Left, l, r);
if (r > now->Mid) B = Query (now->Right, l, r);
A.x += B.x, A.y += B.y;
A.x2 += B.x2, A.xy += B.xy;
return A;
} public : inline void Build (int l, int r) { return Build (Root, l, r); } inline void Change_1 (int l, int r, double s, double t)
{
return Change_1 (Root, l, r, s, t);
} inline void Change_2 (int l, int r, double s, double t)
{
return Change_2 (Root, l, r, s, t);
} inline void Query (int l, int r)
{
D res = Query (Root, l, r); double s = r - l + ;
double b = res.xy - s * (res.x / s) * (res.y / s);
b /= res.x2 - s * (res.x / s) * (res.x / s);
printf ("%.10lf\n", b);
}
}; Segment_Tree Seg; int Main ()
{
fread (buf, , BUF, stdin);
int N, M; read (N), read (M);
register int i; int x;
for (i = ; i <= N; ++ i)
read (x), _x[i] = (double) x;
for (i = ; i <= N; ++ i)
read (x), _y[i] = (double) x;
int type, y, s, t;
for (i = ; i <= N; ++ i)
_i[i] = _i[i - ] + i;
for (i = ; i <= N; ++ i)
i2[i] = i2[i - ] + i * i;
Seg.Build (, N);
for (i = ; i <= M; ++ i)
{
read (type);
if (type == )
{
read (x), read (y);
Seg.Query (x, y);
}
else if (type == )
{
read (x), read (y), read (s), read (t);
Seg.Change_1 (x, y, (double) s, (double) t);
}
else if (type == )
{
read (x), read (y), read (s), read (t);
Seg.Change_2 (x, y, (double) s, (double) t);
}
} return ;
}
int ZlycerQan = Main ();
int main (int argc, char *argv[]) {;}
/*
BZOJ 4821: [Sdoi2017]相关分析 耗费了整整一下午的时间+晚上的些时间 实在是调不出来了。。。 */
#include <cstdio> #define Max 100090
#define INF 1e9 #define DEBUG printf ("%lf %lf %lf %lf\n", now->x, now->y, now->xy, now->pow_two_x); void read (int &now)
{
register char word = getchar ();
bool temp = false;
for (now = ; word < '' || word > ''; word = getchar ())
if (word == '-')
temp = true;
for (; word >= '' && word <= ''; now = now * + word - '', word = getchar ());
if (temp)
now = -now;
} int N, M; double _x[Max], _y[Max];
double sum_i[Max], sum_i_2[Max]; struct Data
{
double S, T;
}; struct S_D
{
S_D *Left, *Right;
int l, r, Mid; Data Tag_1, Tag_2; double xy;
double x, y;
double pow_two_x; inline void Up ()
{
this->x = this->Left->x + this->Right->x;
this->y = this->Left->y + this->Right->y; this->xy = this->Left->xy + this->Right->xy; this->pow_two_x = this->Left->pow_two_x + this->Right->pow_two_x;
} S_D (int __l, int __r) : l (__l), r (__r)
{
Left = Right = NULL;
Mid = __l + __r >> ; x = y = 0.0;
pow_two_x = xy = 0.0; Tag_1.S = Tag_1.T = 0.0;
Tag_2.S = Tag_2.T = INF;
} inline void Push_Down_2 (double S, double T)
{
this->x = (this->r - this->l + ) * S + sum_i[this->r] - sum_i[this->l - ];
this->y = (this->r - this->l + ) * T + sum_i[this->r] - sum_i[this->l - ]; this->xy = (this->r - this->l + ) * S * T + (S + T) * (sum_i[this->r] - sum_i[this->l - ]) + sum_i_2[this->r] - sum_i_2[this->l - ]; this->pow_two_x = (this->r - this->l + ) * S * S + * S * (sum_i[this->r] - sum_i[this->l - ]) + sum_i_2[this->r] - sum_i_2[this->l - ]; this->Tag_1.S = this->Tag_1.T = 0.0; this->Tag_2.S = S;
this->Tag_2.T = T;
} inline void Down ()
{
if (this->Tag_1.S || this->Tag_1.T)
{
bool temp = false;
if (this->Left->Tag_2.S != INF || this->Left->Tag_2.T != INF)
{
temp = true;
this->Left->Push_Down_2 (this->Tag_1.S + this->Left->Tag_2.S, this->Tag_1.T + this->Left->Tag_2.T);
}
if (temp == false)
{
this->Left->xy += this->Tag_1.T * this->Left->x + this->Tag_1.S * this->Left->y + (this->Left->r - this->Left->l + ) * this->Tag_1.S * this->Tag_1.T; this->Left->pow_two_x += 2.0 * this->Tag_1.S * this->Left->x + (this->Left->r - this->l + ) * this->Tag_1.S * this->Tag_1.S; this->Left->x += (this->Left->r - this->Left->l + ) * this->Tag_1.S;
this->Left->y += (this->Left->r - this->Left->l + ) * this->Tag_1.T; this->Left->Tag_1.S += this->Tag_1.S;
this->Left->Tag_1.T += this->Tag_1.T;
}
temp = false; if (this->Right->Tag_2.S != INF || this->Right->Tag_2.T != INF)
{
temp = true;
this->Right->Push_Down_2 (this->Tag_1.S + this->Right->Tag_2.S, this->Tag_1.T + this->Right->Tag_2.T);
}
if (temp == false)
{
this->Right->xy += this->Tag_1.T * this->Right->x + this->Tag_1.S * this->Right->y + (this->Right->r - this->Right->l + ) * this->Tag_1.S * this->Tag_1.T; this->Right->pow_two_x += 2.0 * this->Tag_1.S * this->Right->x + (this->Right->r - this->l + ) * this->Tag_1.S * this->Tag_1.S; this->Right->x += (this->Right->r - this->Right->l + ) * this->Tag_1.S;
this->Right->y += (this->Right->r - this->Right->l + ) * this->Tag_1.T; this->Right->Tag_1.S += this->Tag_1.S;
this->Right->Tag_1.T += this->Tag_1.T; }
this->Tag_1.S = this->Tag_1.T = 0.0;
}
if (this->Tag_2.S != INF || this->Tag_2.T != INF)
{ this->Left->Push_Down_2 (this->Tag_2.S, this->Tag_2.T);
this->Right->Push_Down_2 (this->Tag_2.S, this->Tag_2.T); this->Tag_2.S = this->Tag_2.T = INF;
}
}
}; #define DE printf ("%lf %lf %lf %lf\n", Answer_x, Answer_y, Answer_xy, Answer_x_2); double Answer_x, Answer_y;
double Answer_xy, Answer_x_2; class Segment_Tree_Type
{ private : S_D *Root; void __Build_ (S_D *&now, int l, int r)
{
now = new S_D (l, r);
if (l == r)
{
now->x = _x[l];
now->y = _y[r];
now->xy = now->x * now->y;
now->pow_two_x = now->x * now->x; return ;
}
__Build_ (now->Left, l, now->Mid);
__Build_ (now->Right, now->Mid + , r); now->Up ();
} void __Change_1_ (S_D *&now, int l, int r, double S, double T)
{
if (l <= now->l && now->r <= r)
{
bool temp = false;
if (now->Tag_2.S != INF || now->Tag_2.T != INF)
{
temp = true;
now->Push_Down_2 (now->Tag_2.S + S, now->Tag_2.T + T);
}
if (temp == false)
{
now->xy += T * now->x + S * now->y + (now->r - now->l + ) * S * T;
now->pow_two_x += * S * now->x + (now->r - now->l + ) * S * S; now->x += (now->r - now->l + ) * S;
now->y += (now->r - now->l + ) * T;
now->Tag_1.S += S;
now->Tag_1.T += T;
}
// DEBUG
return ;
}
now->Down ();
if (l <= now->Mid)
__Change_1_ (now->Left, l, r, S, T);
if (r > now->Mid)
__Change_1_ (now->Right, l, r, S, T);
now->Up ();
} void __Change_2_ (S_D *&now, int l, int r, double S, double T)
{
if (l <= now->l && now->r <= r)
{
now->Push_Down_2 (S, T);
// DEBUG
return ;
}
now->Down ();
if (l <= now->Mid)
__Change_2_ (now->Left, l, r, S, T);
if (r > now->Mid)
__Change_2_ (now->Right, l, r, S, T);
now->Up ();
} void __Query_ (S_D *&now, int l, int r)
{
if (l <= now->l && now->r <= r)
{
Answer_x += now->x;
Answer_y += now->y;
Answer_xy += now->xy;
Answer_x_2 += now->pow_two_x;
// DEBUG
return ;
}
now->Down ();
if (l <= now->Mid)
__Query_ (now->Left, l, r);
if (r > now->Mid)
__Query_ (now->Right, l, r); now->Up ();
}
public : inline void Build (int l, int r)
{
return __Build_ (Root, l, r);
} inline void Change_First (int l, int r, double S, double T)
{
return __Change_1_ (Root, l, r, S, T);
} inline void Change_Second (int l, int r, double S, double T)
{
return __Change_2_ (Root, l, r, S, T);
} inline double Query (int l, int r)
{
Answer_x = Answer_y = ;
Answer_xy = Answer_x_2 = ;
__Query_ (Root, l, r);
// DE
double a = (r - l + ) * Answer_xy - Answer_x * Answer_y;
double b = (r - l + ) * Answer_x_2 - Answer_x * Answer_x;
return a / b;
}
}; Segment_Tree_Type Seg; #define Local int main (int argc, char *argv[])
{
#ifdef Local freopen ("relative.in", "r", stdin);
freopen ("relative.out", "w", stdout); #endif read (N);
read (M);
int x;
for (int i = ; i <= N; i ++)
{
sum_i[i] = sum_i[i - ] + i;
sum_i_2[i] = sum_i_2[i - ] + 1.0 * i * i;
}
for (int i = ; i <= N; i ++)
scanf ("%lf", &_x[i]);
for (int i = ; i <= N; i ++)
scanf ("%lf", &_y[i]); Seg.Build (, N);
for (int y, z, s, type; M --; )
{
read (type); if (type == )
{
read (x);
read (y);
printf ("%.10lf\n", Seg.Query (x, y));
}
else if (type == )
{
read (x);
read (y);
read (z);
read (s); Seg.Change_First (x, y, z, s);
}
else
{
read (x);
read (y);
read (z);
read (s);
Seg.Change_Second (x, y, z, s);
}
}
return ;
}
(WA)BZOJ 4821: [Sdoi2017]相关分析的更多相关文章
- ●BZOJ 4821 [Sdoi2017]相关分析
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=4821 题解: 线段树是真的恶心,(也许是我的方法麻烦了一些吧)首先那个式子可以做如下化简: ...
- BZOJ.4821.[SDOI2017]相关分析(线段树)
BZOJ LOJ 洛谷 恶心的拆式子..然后就是要维护\(\sum x_i,\ \sum y_i,\ \sum x_iy_i,\ \sum x_i^2\). 操作三可以看成初始化一遍,然后同操作二. ...
- bzoj 4821 [Sdoi2017]相关分析
题面 https://www.lydsy.com/JudgeOnline/problem.php?id=4821 题解 做法显然 就是维护一颗线段树 里面装4个东西 区间x的和 区间y的和 区间$x^ ...
- BZOJ 4821 [Sdoi2017]相关分析 ——线段树
打开题面,看到许多$\sum$ woc,好神啊,SDOI好强啊 然后展开之后,woc,SDOI好弱啊,怎么T3出个线段树裸题啊. 最后写代码的时候,woc,SDOI怎么出个这么码农的题啊,怎么调啊. ...
- BZOJ 4821: [Sdoi2017]相关分析 线段树 + 卡精
考试的时候切掉了,然而卡精 + 有一个地方忘开 $long long$,完美挂掉 $50$pts. 把式子化简一下,然后直接拿线段树来维护即可. Code: // luogu-judger-enabl ...
- 4821: [Sdoi2017]相关分析
4821: [Sdoi2017]相关分析 链接 分析: 大力拆式子,化简,然后线段树.注意精度问题与爆longlong问题. 代码: #include<cstdio> #include&l ...
- BZOJ4817 SDOI2017 相关分析
4821: [Sdoi2017]相关分析 Time Limit: 10 Sec Memory Limit: 128 MBSec Special Judge Description Frank对天文 ...
- 【BZOJ4821】[SDOI2017]相关分析(线段树)
[BZOJ4821][SDOI2017]相关分析(线段树) 题面 BZOJ 洛谷 题解 看看询问要求的东西是什么.把所有的括号拆开,不难发现要求的就是\(\sum x,\sum y,\sum xy,\ ...
- [Sdoi2017]相关分析 [线段树]
[Sdoi2017]相关分析 题意:沙茶线段树 md其实我考场上还剩一个多小时写了40分 其实当时写正解也可以吧1h也就写完了不过还要拍一下 正解代码比40分短2333 #include <io ...
随机推荐
- Shell脚本基础学习
Shell脚本基础学习 当你在类Unix机器上编程时, 或者参与大型项目如k8s等, 某些框架和软件的安装都是使用shell脚本写的. 学会基本的shell脚本使用, 让你走上人生巅峰, 才怪. 学会 ...
- 自动化测试之if __name__ == '__main__'未运行
自动化测试之if __name__ == '__main__'未运行 添加Count类 calculator.py: class Count: def __init__(self,a,b): self ...
- Base64编码为什么会使数据量变大
现在工作中把视频转成base64发现数据量过大无法下载. 1.为什么base64编码会使数据量变大呢? Base64编码的思想是是采用64个基本的ASCII码字符对数据进行重新编码.它将需要编码的数据 ...
- 在论坛中出现的比较难的sql问题:1(字符串分拆+行转列问题 SQL遍历截取字符串)
原文:在论坛中出现的比较难的sql问题:1(字符串分拆+行转列问题 SQL遍历截取字符串) 最近,在论坛中,遇到了不少比较难的sql问题,虽然自己都能解决,但发现过几天后,就记不起来了,也忘记解决的方 ...
- XML和JSON序列化以及反序列化
1.将文件保存序列化至文档中,然后再读取: //首先创建可序列化的实体类 [Serializable] public class Message { public string Name { get; ...
- Linux每隔1秒kill掉cpu大于50%的进程
1.新建/test/killcpu.sh shell脚本 并授予权限0755#!/bin/bashps axf -o "pid %cpu" | awk '{if($2>=50 ...
- 听课笔记--DP--最大子矩阵和
最大子矩阵问题 给定一个n*n(0<n<=120)的矩阵, 矩阵内元素有正有负, 请找到此矩阵的内部元素和最大的子矩阵 样例输入: 4 0 -2 -7 0 9 2 -6 2 -4 ...
- springboot启动流程(四)application配置文件加载过程
所有文章 https://www.cnblogs.com/lay2017/p/11478237.html 触发监听器加载配置文件 在上一篇文章中,我们看到了Environment对象的创建方法.同时也 ...
- python 解析Hdfs上的数据文件
python想直接读取hadoop上的文件内容,一番操作,头发掉了几根,也没能解析出来parquet文件类型的文件. 本博文简单讲解一下TEXTFILE文件格式的解析: 需要安装模块hdfs from ...
- Linq以本周和本月为条件的Sql,Liqn查询本周,Linq查询本月
//计算本周时间 时间 > DateTime.Now.AddDays(-Convert.ToInt32(DateTime.Now.Date.DayOfWeek) //计算本月时间 时间 > ...