题目大意:

太长了略 洛谷题面传送门

嗯,数学题

感觉考试要是出这种题我就死翘翘了【逃

不用想都知道要$LCT$维护断边连边,但询问该如何处理呢

利用题目给出的公式

$f(x)=\sum_{i=0}^{inf} \frac{f^{(i)}(x_{0})(x-x_{0})^{i}}{i!}$

发现,同阶的导变成了常量,可以直接相加了!

我们只需要求出$\sum_{u to v} f^{(i)}(x_{0})$,用$LCT$维护,每次把$x$带入即可

$x_{0}$可以选择0.5

我们可以主动卡精度,每个节点只需要求出对应函数的1~13阶导即可

注意别把第三个操作的$f++$了= =

 #include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N1 100100
#define M1 2010
#define S1 (N1<<1)
#define T1 (N1<<2)
#define ll long long
#define uint unsigned int
#define rint register int
#define ull unsigned long long
#define dd double
#define ld long double
#define il inline
#define inf 1000000000
using namespace std; const ld X=0.5;
int gint()
{
int ret=,fh=;char c=getchar();
while(c<''||c>''){if(c=='-')fh=-;c=getchar();}
while(c>=''&&c<=''){ret=ret*+c-'';c=getchar();}
return ret*fh;
}
int n,m,T,type;
int tot;
struct LCT{
int ch[N1][],fa[N1],rev[N1],type[N1];
ld a[N1],b[N1],f[N1][],sum[N1][];
inline int idf(int x){return ch[fa[x]][]==x?:;}
inline void revers(int x){swap(ch[x][],ch[x][]),rev[x]^=;}
inline int isroot(int x){return (ch[fa[x]][]==x||ch[fa[x]][]==x)?:;}
void update(int x)
{
memset(f[x],,sizeof(f[x]));
if(type[x]==){
f[x][]=sin(a[x]*X+b[x]),f[x][]=a[x]*cos(a[x]*X+b[x]);
for(int i=;i<=;i++)
f[x][i]=-a[x]*a[x]*f[x][i-];
}else if(type[x]==){
f[x][]=exp(X*a[x]+b[x]);
for(int i=;i<=;i++)
f[x][i]=a[x]*f[x][i-];
}else{
f[x][]=a[x]*X+b[x],f[x][]=a[x];
}
}
inline void pushup(int x)
{
for(rint i=;i<=;i++)
sum[x][i]=sum[ch[x][]][i]+sum[ch[x][]][i]+f[x][i];
}
void pushdown(int x)
{
if(rev[x])
{
if(ch[x][]) revers(ch[x][]);
if(ch[x][]) revers(ch[x][]);
rev[x]^=;
}
}
int stk[N1],tp;
void rot(int x)
{
int y=fa[x],ff=fa[y],px=idf(x),py=idf(y);
if(!isroot(y)) ch[ff][py]=x; fa[x]=ff;
fa[ch[x][px^]]=y,ch[y][px]=ch[x][px^];
ch[x][px^]=y,fa[y]=x;
pushup(y),pushup(x);
}
void splay(int x)
{
int y=x; stk[++tp]=x;
while(!isroot(y)){stk[++tp]=fa[y],y=fa[y];}
while(tp){pushdown(stk[tp--]);}
while(!isroot(x))
{
y=fa[x];
if(isroot(y)) rot(x);
else if(idf(y)==idf(x)) rot(y),rot(x);
else rot(x),rot(x);
}
}
void access(int x)
{
for(int y=;x;y=x,x=fa[x])
splay(x),ch[x][]=y,pushup(x);
}
void mkroot(int x){access(x),splay(x),revers(x);}
void split(int x,int y){mkroot(x),access(y),splay(y);}
int fdroot(int x)
{
access(x),splay(x);
while(ch[x][]) pushdown(ch[x][]),x=ch[x][];
splay(x); return x;
}
void link(int x,int y)
{
split(x,y);
/*if(findroot(y)!=x)*/ fa[x]=y;
}
void cut(int x,int y)
{
split(x,y);
if(!ch[x][]&&fa[x]==y&&ch[y][]==x)
fa[x]=ch[y][]=,pushup(y);
}
void magic(int x,int p,dd A,dd B)
{
splay(x);
type[x]=p; a[x]=A; b[x]=B;
update(x); pushup(x);
}
ld query(int x,int y,dd w,int &fl)
{
split(x,y); if(fdroot(y)!=x) {fl=-;return ;}
ld mul=,ans=sum[x][],pw=;
for(int i=;i<=;i++)
{
mul*=i; pw*=(w-X);
ans+=sum[x][i]*pw/mul;
}
return ans;
}
void init()
{
for(int i=;i<=n;i++)
{
type[i]=gint();
scanf("%Lf%Lf",&a[i],&b[i]);
update(i);
}
}
}lct; char str[]; int main()
{
freopen("t2.in","r",stdin);
//freopen("a.out","w",stdout);
scanf("%d%d%s",&n,&m,str);
int i,j,x,y,fl=; ld A,B,ans;
lct.init();
for(j=;j<=m;j++)
{
scanf("%s",str); x=gint(),y=gint();
if(str[]=='a'){
x++,y++;
lct.link(x,y);
}else if(str[]=='d'){
x++,y++;
lct.cut(x,y);
}else if(str[]=='m'){
x++;
scanf("%Lf%Lf",&A,&B);
lct.magic(x,y,A,B);
}else{
x++,y++;
scanf("%Lf",&A); fl=;
ans=lct.query(x,y,A,fl);
if(fl==-) puts("unreachable");
else printf("%.12Lf\n",ans);
}
}
return ;
}

/*

既然动态断边连边维护一个树形结构,肯定是要用LCT啦

那么怎么维护呢= =

每个人智商都不同,所以把它带入到每个点的函数里,会T

我们要想个办法,快速处理询问

翻一翻题面,诶!这个公式是干嘛的呢?

f(x)=\sum_{i=0}^{inf} \frac{f^{(i)}(x_{0})(x-x_{0})^{i}}{i!}

x_{0}貌似是随便取的诶,作为一名强迫症肯定要取中间值0.5= =

我怎么说了这么多废话*/

BZOJ 5020 [THUWC2017]Drown in the math ocean (LCT+求导)的更多相关文章

  1. 【Math】矩阵求导

    https://en.wikipedia.org/wiki/Matrix_calculus http://blog.sina.com.cn/s/blog_7959e7ed0100w2b3.html

  2. bzoj 5020(洛谷4546) [THUWC 2017]在美妙的数学王国中畅游——LCT+泰勒展开

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=5020 https://www.luogu.org/problemnew/show/P4546 ...

  3. 【BZOJ 3561】 3561: DZY Loves Math VI (莫比乌斯,均摊log)

    3561: DZY Loves Math VI Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 205  Solved: 141 Description ...

  4. 【BZOJ 3560】 3560: DZY Loves Math V (欧拉函数)

    3560: DZY Loves Math V Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 241  Solved: 133 Description ...

  5. 【BZOJ】1754: [Usaco2005 qua]Bull Math

    [算法]高精度乘法 #include<cstdio> #include<algorithm> #include<cstring> using namespace s ...

  6. bzoj 5020: [THUWC 2017]在美妙的数学王国中畅游【泰勒展开+LCT】

    参考:https://www.cnblogs.com/CQzhangyu/p/7500328.html --其实理解了泰勒展开之后就是水题呢可是我还是用了两天时间来搞懂啊 泰勒展开是到正无穷的,但是因 ...

  7. 洛谷 P4546 & bzoj 5020 在美妙的数学王国中畅游 —— LCT+泰勒展开

    题目:https://www.luogu.org/problemnew/show/P4546 先写了个55分的部分分,直接用LCT维护即可,在洛谷上拿了60分: 注意各处 pushup,而且 spla ...

  8. BZOJ 1185: [HNOI2007]最小矩形覆盖-旋转卡壳法求点集最小外接矩形(面积)并输出四个顶点坐标-备忘板子

    来源:旋转卡壳法求点集最小外接矩形(面积)并输出四个顶点坐标 BZOJ又崩了,直接贴一下人家的代码. 代码: #include"stdio.h" #include"str ...

  9. 【BZOJ】2049: [Sdoi2008]Cave 洞穴勘测(lct/并查集)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2049 bzoj挂了..在wikioi提交,,1A-写lct的速度越来越快了-都不用debug-- 新 ...

随机推荐

  1. javaSE常用的英语单词

    1.continut 使......继续 2.break 打破 3.switch 开关:转换:鞭子 4.case 实例:情况:箱 5.Object 目标:物体 6.Class 阶级:班级:种类 7.p ...

  2. 在 vue-test-utils 中 mock 全局对象

    vue-test-utils 提供了一种 mock 掉 Vue.prototype 的简单方式,不但对测试用例适用,也可以为所有测试设置默认的 mock. mocks 加载选项 mocks 加载选项 ...

  3. 《代码敲不队》第八次团队作业:Alpha冲刺 第三天

    项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 团队名称 代码敲不队 作业学习目标 掌握软件编码实现的工程要求. 团队项目github仓库地址链接 GitH ...

  4. Hibernate 一对多

    表与表之间关系回顾(重点) 1 一对多 (1)分类和商品关系,一个分类里面有多个商品,一个商品只能属于一个分类 (2)客户和联系人是一对多关系 - 客户:与公司有业务往来,百度.新浪.360 - 联系 ...

  5. 洛谷——P1115 最大子段和

    https://www.luogu.org/problem/show?pid=1115#sub 题目描述 给出一段序列,选出其中连续且非空的一段使得这段和最大. 输入输出格式 输入格式: 输入文件ma ...

  6. 一起写RPC

    http://blog.csdn.net/linuu?viewmode=contents

  7. 基于FPGA的VGA可移植模块终极设计

    一.VGA的诱惑 首先,VGA的驱动,这事,一般的单片机是办不到的:由于FPGA的速度,以及并行的优势,加上可现场配置的优势,VGA的配置,只有俺们FPGA可以胜任,也只有FPGA可以随心所欲地配置( ...

  8. 0x02 枚举、模拟、递推

    1.TYVJ1266(这站是不是已经倒闭了啊) USACO陈年老题,对于这种开关问题啊,最多只按一次,而且第一行随便按完下面的就全确定了,类似的还有固定翻转一个长度的区间,这个也是最多翻一次的而且翻的 ...

  9. FastDFS分布式文件系统研究

    FastDFS分布式文件系统 这个主要是针对应用型的,很使用,特别是对于电商等 一.编译安装 ubuntu平台: apt-get install libevent(这个默认就有,没有就装下) libe ...

  10. python绘制caffe中网络模型

    caffe-master/python/draw_net.py 实现绘制caffe中定义的网络模型功能,将.prototxt文件可视化. 需要先安装pydot和protobuf工具 通过Anacond ...