题目大意:

太长了略 洛谷题面传送门

嗯,数学题

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

不用想都知道要$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++$了= =

  1. #include <cmath>
  2. #include <vector>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <algorithm>
  6. #define N1 100100
  7. #define M1 2010
  8. #define S1 (N1<<1)
  9. #define T1 (N1<<2)
  10. #define ll long long
  11. #define uint unsigned int
  12. #define rint register int
  13. #define ull unsigned long long
  14. #define dd double
  15. #define ld long double
  16. #define il inline
  17. #define inf 1000000000
  18. using namespace std;
  19.  
  20. const ld X=0.5;
  21. int gint()
  22. {
  23. int ret=,fh=;char c=getchar();
  24. while(c<''||c>''){if(c=='-')fh=-;c=getchar();}
  25. while(c>=''&&c<=''){ret=ret*+c-'';c=getchar();}
  26. return ret*fh;
  27. }
  28. int n,m,T,type;
  29. int tot;
  30. struct LCT{
  31. int ch[N1][],fa[N1],rev[N1],type[N1];
  32. ld a[N1],b[N1],f[N1][],sum[N1][];
  33. inline int idf(int x){return ch[fa[x]][]==x?:;}
  34. inline void revers(int x){swap(ch[x][],ch[x][]),rev[x]^=;}
  35. inline int isroot(int x){return (ch[fa[x]][]==x||ch[fa[x]][]==x)?:;}
  36. void update(int x)
  37. {
  38. memset(f[x],,sizeof(f[x]));
  39. if(type[x]==){
  40. f[x][]=sin(a[x]*X+b[x]),f[x][]=a[x]*cos(a[x]*X+b[x]);
  41. for(int i=;i<=;i++)
  42. f[x][i]=-a[x]*a[x]*f[x][i-];
  43. }else if(type[x]==){
  44. f[x][]=exp(X*a[x]+b[x]);
  45. for(int i=;i<=;i++)
  46. f[x][i]=a[x]*f[x][i-];
  47. }else{
  48. f[x][]=a[x]*X+b[x],f[x][]=a[x];
  49. }
  50. }
  51. inline void pushup(int x)
  52. {
  53. for(rint i=;i<=;i++)
  54. sum[x][i]=sum[ch[x][]][i]+sum[ch[x][]][i]+f[x][i];
  55. }
  56. void pushdown(int x)
  57. {
  58. if(rev[x])
  59. {
  60. if(ch[x][]) revers(ch[x][]);
  61. if(ch[x][]) revers(ch[x][]);
  62. rev[x]^=;
  63. }
  64. }
  65. int stk[N1],tp;
  66. void rot(int x)
  67. {
  68. int y=fa[x],ff=fa[y],px=idf(x),py=idf(y);
  69. if(!isroot(y)) ch[ff][py]=x; fa[x]=ff;
  70. fa[ch[x][px^]]=y,ch[y][px]=ch[x][px^];
  71. ch[x][px^]=y,fa[y]=x;
  72. pushup(y),pushup(x);
  73. }
  74. void splay(int x)
  75. {
  76. int y=x; stk[++tp]=x;
  77. while(!isroot(y)){stk[++tp]=fa[y],y=fa[y];}
  78. while(tp){pushdown(stk[tp--]);}
  79. while(!isroot(x))
  80. {
  81. y=fa[x];
  82. if(isroot(y)) rot(x);
  83. else if(idf(y)==idf(x)) rot(y),rot(x);
  84. else rot(x),rot(x);
  85. }
  86. }
  87. void access(int x)
  88. {
  89. for(int y=;x;y=x,x=fa[x])
  90. splay(x),ch[x][]=y,pushup(x);
  91. }
  92. void mkroot(int x){access(x),splay(x),revers(x);}
  93. void split(int x,int y){mkroot(x),access(y),splay(y);}
  94. int fdroot(int x)
  95. {
  96. access(x),splay(x);
  97. while(ch[x][]) pushdown(ch[x][]),x=ch[x][];
  98. splay(x); return x;
  99. }
  100. void link(int x,int y)
  101. {
  102. split(x,y);
  103. /*if(findroot(y)!=x)*/ fa[x]=y;
  104. }
  105. void cut(int x,int y)
  106. {
  107. split(x,y);
  108. if(!ch[x][]&&fa[x]==y&&ch[y][]==x)
  109. fa[x]=ch[y][]=,pushup(y);
  110. }
  111. void magic(int x,int p,dd A,dd B)
  112. {
  113. splay(x);
  114. type[x]=p; a[x]=A; b[x]=B;
  115. update(x); pushup(x);
  116. }
  117. ld query(int x,int y,dd w,int &fl)
  118. {
  119. split(x,y); if(fdroot(y)!=x) {fl=-;return ;}
  120. ld mul=,ans=sum[x][],pw=;
  121. for(int i=;i<=;i++)
  122. {
  123. mul*=i; pw*=(w-X);
  124. ans+=sum[x][i]*pw/mul;
  125. }
  126. return ans;
  127. }
  128. void init()
  129. {
  130. for(int i=;i<=n;i++)
  131. {
  132. type[i]=gint();
  133. scanf("%Lf%Lf",&a[i],&b[i]);
  134. update(i);
  135. }
  136. }
  137. }lct;
  138.  
  139. char str[];
  140.  
  141. int main()
  142. {
  143. freopen("t2.in","r",stdin);
  144. //freopen("a.out","w",stdout);
  145. scanf("%d%d%s",&n,&m,str);
  146. int i,j,x,y,fl=; ld A,B,ans;
  147. lct.init();
  148. for(j=;j<=m;j++)
  149. {
  150. scanf("%s",str); x=gint(),y=gint();
  151. if(str[]=='a'){
  152. x++,y++;
  153. lct.link(x,y);
  154. }else if(str[]=='d'){
  155. x++,y++;
  156. lct.cut(x,y);
  157. }else if(str[]=='m'){
  158. x++;
  159. scanf("%Lf%Lf",&A,&B);
  160. lct.magic(x,y,A,B);
  161. }else{
  162. x++,y++;
  163. scanf("%Lf",&A); fl=;
  164. ans=lct.query(x,y,A,fl);
  165. if(fl==-) puts("unreachable");
  166. else printf("%.12Lf\n",ans);
  167. }
  168. }
  169. return ;
  170. }

/*

既然动态断边连边维护一个树形结构,肯定是要用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. BZOJ 2959 长跑 (LCT+并查集)

    题面:BZOJ传送门 当成有向边做的发现过不去样例,改成无向边就忘了原来的思路.. 因为成环的点一定都能取到,我们把它们压成一个新点,权值为环上所有点的权值和 这样保证了图是一颗森林 每次询问转化为, ...

  2. [poj 3539] Elevator (同余类bfs)

    Description Edward works as an engineer for Non-trivial Elevators: Engineering, Research and Constru ...

  3. 园区IP地址规划(非常详细)

    转:https://mp.weixin.qq.com/s/Zlm7x5eunIYLAG7Sp0yVCQ 经过这些年工作,接触从几万.几十万到上亿的项目都有: 我简单总结了接触的大部分的项目,将园区网核 ...

  4. Unknown tag (s:property).

    Unknown tag (s:property). 在jsp文件中加入此句话:<%@ taglib uri="/struts-tags" prefix="s&quo ...

  5. MySQL 与 MongoDB的操作对比

    MySQL与MongoDB都是开源的常用数据库,但是MySQL是传统的关系型数据库,MongoDB则是非关系型数据库,也叫文档型数据库,是一种NoSQL的数据库.它们各有各的优点,关键是看用在什么地方 ...

  6. idea常用方便的快捷键

    Ctrl+D 复制行Ctrl+F 查找文本Ctrl+G 定位到某行Ctrl+H 显示类结构图(类的继承层次)Ctrl+I 实现方法ctrl+J 显示所有快捷键模板ctrl+k 提交代码到SVNCrtl ...

  7. CF802G Fake News (easy)

    CF802G Fake News (easy) 题意翻译 给定一个字符串询问能否听过删除一些字母使其变为“heidi” 如果可以输出“YES”,不然为“NO” 题目描述 As it's the fir ...

  8. Chromium网页输入事件捕捉和手势检測过程分析

    连续的输入事件可能会产生一定的手势操作.比如滑动手势和捏合手势. 在Chromium中,网页的输入事件是在Browser进程中捕捉的.Browser进程捕获输入事件之后,会进行手势操作检測.检測出来的 ...

  9. 分享:Android系统的经常使用权限整理

    1.ACCES_NETWORK_STATE      同意应用程序获取网络状态信息的权限 2.ACCESS_WIFI_STATE          同意应用程序获取Wi-Fi网络状态的权限 3.BAT ...

  10. MantisBT 问题分配显示 姓名

    MantisBT 在提交问题的时候,系统默认"分配"给备选账号,而不是姓名. 这样在使用的时候很不便. 能够通过改动配置文件来改变,找到MantisBT根文件夹下文件config_ ...