[THUWC2017]在美妙的数学王国中畅游

e和sin信息不能直接合并

泰勒展开,大于21次太小,认为是0,保留前21次多项式即可

然后就把e,sin ,kx+b都变成多项式了,pushup合并

上LCT

// luogu-judger-enable-o2
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define reg register int
#define il inline
#define fi first
#define se second
#define mk(a,b) make_pair(a,b)
#define numb (ch^'0')
#define ld double
using namespace std;
typedef long long ll;
template<class T>il void rd(T &x){
char ch;x=;bool fl=false;
while(!isdigit(ch=getchar()))(ch=='-')&&(fl=true);
for(x=numb;isdigit(ch=getchar());x=x*+numb);
(fl==true)&&(x=-x);
}
template<class T>il void output(T x){if(x/)output(x/);putchar(x%+'');}
template<class T>il void ot(T x){if(x<) putchar('-'),x=-x;output(x);putchar(' ');}
template<class T>il void prt(T a[],int st,int nd){for(reg i=st;i<=nd;++i) ot(a[i]);putchar('\n');} namespace Miracle{
const int N=1e5+;
const int K=;
int n,m;
struct Poly{
ld a[K];
Poly(){memset(a,,sizeof a);}
il ld &operator[](const int &x){return a[x];}
il const ld &operator[](const int &x) const {return a[x];}
Poly friend operator +(const Poly &a,const Poly &b){
Poly c;
for(reg i=;i<K;++i){
c.a[i]=a.a[i]+b.a[i];
}
return c;
}
ld calc(ld x){
ld tmp=,ret=;
for(reg i=;i<K;++i){
ret=ret+a[i]*tmp;
tmp=tmp*x;
}
return ret;
}
};
int C[][];
ld jie[K],ma[K],mb[K];
Poly exp(double a,double b){
Poly ret;
ma[]=;mb[]=;
for(reg i=;i<K;++i){
ma[i]=ma[i-]*a;
mb[i]=mb[i-]*b;
}
for(reg i=;i<K;++i){
for(reg j=;j<=i;++j){
ret.a[j]+=C[i][j]*ma[j]*mb[i-j]*jie[i];
}
}
return ret;
}
Poly sin(double a,double b){
Poly ret;
ma[]=;mb[]=;
for(reg i=;i<K;++i){
ma[i]=ma[i-]*a;
mb[i]=mb[i-]*b;
}
for(reg i=;i<K;i+=){
for(reg j=;j<=i;++j){
if(((i-)/)&){
ret.a[j]-=C[i][j]*ma[j]*mb[i-j]*jie[i];
}else{
ret.a[j]+=C[i][j]*ma[j]*mb[i-j]*jie[i];
}
}
}
return ret;
}
Poly init(int typ,double a,double b){
if(typ==) return sin(a,b);
if(typ==) return exp(a,b);
Poly ret;
ret.a[]=a;
ret.a[]=b;
return ret;
}
struct node{
int ch[],fa;
int rev;
Poly f,sum;
}t[N];
#define ls t[x].ch[0]
#define rs t[x].ch[1]
void pushup(int x){
if(!x) return;
t[x].sum=t[ls].sum+t[rs].sum+t[x].f;
}
bool nrt(int x){
return t[t[x].fa].ch[]==x||t[t[x].fa].ch[]==x;
}
void rev(int x){
t[x].rev^=;
swap(ls,rs);
}
void pushdown(int x){
if(t[x].rev){
rev(ls);rev(rs);
t[x].rev=;
}
}
void rotate(int x){
int y=t[x].fa,d=t[y].ch[]==x;
t[t[y].ch[d]=t[x].ch[!d]].fa=y;
if(nrt(y)) t[t[x].fa=t[y].fa].ch[t[t[y].fa].ch[]==y]=x;
else t[x].fa=t[y].fa;
t[t[x].ch[!d]=y].fa=x;
pushup(y);
}
int sta[N];
void splay(int x){
int y=x,z=;
sta[++z]=x;
while(nrt(y)) y=t[y].fa,sta[++z]=y;
while(z) pushdown(sta[z--]);
while(nrt(x)){
y=t[x].fa,z=t[y].fa;
if(nrt(y)){
rotate((t[y].ch[]==x)==(t[z].ch[]==y)?y:x);
}
rotate(x);
}
pushup(x);
}
void access(int x){
for(reg y=;x;y=x,x=t[x].fa){
splay(x);t[x].ch[]=y;pushup(x);
}
}
void makert(int x){
access(x);splay(x);rev(x);
}
void link(int x,int y){
makert(x);t[x].fa=y;
}
void split(int x,int y){
makert(x);access(y);splay(y);
}
void cut(int x,int y){
split(x,y);
t[y].ch[]=t[x].fa=;
pushup(y);
}
int findrt(int x){
access(x);splay(x);
while(ls) x=ls;
splay(x);
return x;
}
ld query(int x,int y,ld v){
split(x,y);
return t[y].sum.calc(v);
}
char s[];
int main(){
char haha[];
rd(n);rd(m);scanf("%s",haha+); int typ;
ld a,b;
int x,y;
C[][]=;
for(reg i=;i<=K;++i){
C[i][]=;
for(reg j=;j<=K;++j){
C[i][j]=C[i-][j]+C[i-][j-];
}
}
jie[]=jie[]=;
for(reg i=;i<=K;++i){
jie[i]=jie[i-]/i;
}
for(reg i=;i<=n;++i){
rd(typ);scanf("%lf%lf",&a,&b);
t[i].f=init(typ,a,b);
pushup(i);
}
while(m--){
scanf("%s",s+);
if(s[]=='a'){
rd(x);rd(y);
++x;++y;
link(x,y);
}else if(s[]=='d'){
rd(x);rd(y);
++x;++y;
cut(x,y);
}else if(s[]=='m'){
rd(x);rd(typ);scanf("%lf%lf",&a,&b);
++x;
access(x);splay(x);
t[x].f=init(typ,a,b);
pushup(x);
}else {
// cout<<" tr "<<endl;
rd(x);rd(y);scanf("%lf",&a);
++x;++y;
// cout<<x<<" "<<y<<" a "<<a<<endl;
if(findrt(x)==findrt(y)) printf("%.10lf\n",query(x,y,a));
else puts("unreachable");
}
}
return ;
} }
signed main(){
Miracle::main();
return ;
} /*
Author: *Miracle*
Date: 2019/4/11 20:11:40
*/

多项式可以支持合并

[THUWC2017]在美妙的数学王国中畅游的更多相关文章

  1. [BZOJ5020][THUWC2017]在美妙的数学王国中畅游(LCT)

    5020: [THUWC 2017]在美妙的数学王国中畅游 Time Limit: 80 Sec  Memory Limit: 512 MBSec  Special JudgeSubmit: 323  ...

  2. Luogu4546 THUWC2017 在美妙的数学王国中畅游 LCT、泰勒展开

    传送门 题意:反正就是一堆操作 LCT总是和玄学东西放在一起我们不妨令$x_0=0.5$(其实取什么都是一样的,但是最好取在$[0,1]$的范围内),将其代入给出的式子,我们得到的$f(x)$的式子就 ...

  3. [THUWC2017]在美妙的数学王国中畅游 LCT+泰勒展开+求导

    p.s. 复合函数求导时千万不能先带值,再求导. 一定要先将符合函数按照求导的规则展开,再带值. 设 $f(x)=g(h(x))$,则对 $f(x)$ 求导: $f'(x)=h'(x)g'(h(x)) ...

  4. [LOJ2289][THUWC2017]在美妙的数学王国中畅游:Link-Cut Tree+泰勒展开

    分析 又有毒瘤出题人把数学题出在树上了. 根据泰勒展开,有: \[e^x=1+\frac{1}{1!}x+\frac{1}{2!}x^2+\frac{1}{3!}x^3+...\] \[sin(x)= ...

  5. 题解 洛谷 P4546 【[THUWC2017]在美妙的数学王国中畅游】

    首先发现有连边和删边的操作,所以我们肯定要用\(LCT\)来进行维护. 接下来考虑如何进行\(LCT\)上的信息合并. \(f=1\),则函数为\(f(x)=sin(ax+b)\) \(f=2\),则 ...

  6. Luogu P4546 [THUWC2017]在美妙的数学王国中畅游

    题意 题意奇奇怪怪,这里就不写了. \(\texttt{Data Range:}1\leq n\leq 10^5,1\leq m\leq 2\times 10^5\) 题解 为什么你们都是卡在数学方面 ...

  7. 洛谷P4546 [THUWC2017]在美妙的数学王国中畅游 [LCT,泰勒展开]

    传送门 毒瘤出题人卡精度-- 思路 看到森林里加边删边,容易想到LCT. 然而LCT上似乎很难实现往一条链里代一个数进去求和,怎么办呢? 善良的出题人在下方给了提示:把奇怪的函数泰勒展开搞成多项式,就 ...

  8. P4546 [THUWC2017]在美妙的数学王国中畅游

    如果只有第3个操作,那么这就是个sd题,随便lct搞搞就过去了 然后就是一个神仙东西 taylor公式 我不会,看gsy博客https://www.cnblogs.com/zhoushuyu/p/81 ...

  9. BZOJ5020 THUWC2017在美妙的数学王国中畅游(LCT)

    明摆着的LCT,问题在于如何维护答案.首先注意到给出的泰勒展开式,并且所给函数求导非常方便,肯定要用上这玩意.容易想到展开好多次达到精度要求后忽略余项.因为x∈[0,1]而精度又与|x-x0|有关,当 ...

随机推荐

  1. 《Effective C++》设计与声明:条款18-条款25

    条款18:让接口容易被正确使用,不容易被误用 注意使用const,explicit,shared_ptr等来限制接口. 必要时可以创建一些新的类型,限制类型操作,束缚对象等. 注意保持接口的一致性,且 ...

  2. spring AOP源码分析(一)

    对于springAOP的源码分析,我打算分三部分来讲解:1.配置文件的解析,解析为BeanDefination和其他信息然后注册到BeanFactory中:2.为目标对象配置增强行为以及代理对象的生成 ...

  3. Spring 基于XML配置

    基于XML的配置 对于基于XML的配置,Spring 1.0的配置文件采用DTD格式,Spring2.0以后采用Schema格式,后者让不同类型的配罝拥有了自己的命名空间,使得配置文件更具扩展性.此外 ...

  4. Form组件归类

    一.Form类 创建Form类时,主要涉及到 [字段] 和 [插件],字段用于对用户请求数据的验证,插件用于自动生成HTML; 1.Django内置字段如下: 1 Field 2 required=T ...

  5. 从 Aliyun 经典网络迁移到 Aliyun VPC 网络

    由于阿里云策略问题,要求用户从经典网络中全部迁出,搬迁到他们设置的 VPC 网络中.这里的 VPC 大概指的是逻辑上的一个虚拟局域网.即使是实际上你的机器垮机房在阿里云的不同机房.但是他们仍然能从逻辑 ...

  6. JavaScript之Json的使用

    Json字符串转JavaScript对象 <html> <body> <h3>通过 JSON 字符串来创建对象</h3> <p> First ...

  7. ABP 番外篇-容器

    一. @using YD.CloudTimetable.Web.Areas.AppAreaName.Startup @{ ViewBag.CurrentPageName = AppAreaNamePa ...

  8. jedis集群版应用

    1.pom文件添加依赖: 2.创建配置文件 <!-- jedis集群版配置(JedisCluster通过构造传参(2个参数)) --> <bean id="redisCli ...

  9. C#程序中设置全局代理(Global Proxy)

    1. HttpWebRequest类的Proxy属性,只要设置了该属性就能够使用代理了,如下: 1             //设置代理 2         WebProxy WP = new Web ...

  10. Mysql 查看连接数,状态 最大并发数(赞)

    Mysql 查看连接数,状态 最大并发数(赞)   -- show variables like '%max_connections%'; 查看最大连接数 set global max_connect ...