码迷,mamicode.com
首页 > 其他好文 > 详细

多项式反三角函数

时间:2021-04-22 15:58:43      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:三角函数   多项式   bit   ==   ref   函数   gis   bool   tin   

\(\text{Problem}:\)多项式反三角函数

\(\text{Solution}:\)

\[\begin{aligned} (\arcsin A(x))‘&=\cfrac{A‘(x)}{\sqrt{1-A^{2}(x)}}\\arcsin A(x)&=\int\cfrac{A‘(x)}{\sqrt{1-A^{2}(x)}}dx\(\arccos A(x))‘&=-\cfrac{A‘(x)}{\sqrt{1-A^{2}(x)}}\\arccos A(x)&=-\int\cfrac{A‘(x)}{\sqrt{1-A^{2}(x)}}dx\(\arctan A(x))‘&=\cfrac{A‘(x)}{1+A^{2}(x)}\\arctan A(x)&=\int\cfrac{A‘(x)}{1+A^{2}(x)}dx \end{aligned} \]

\(\text{Code}:\)

#include <bits/stdc++.h>
#pragma GCC optimize(3)
//#define int long long
#define ri register
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define is insert
#define es erase
#define vi vector<int>
#define vpi vector<pair<int,int>>
using namespace std; const int N=265010, Mod=998244353;
inline int read()
{
	int s=0, w=1; ri char ch=getchar();
	while(ch<‘0‘||ch>‘9‘) { if(ch==‘-‘) w=-1; ch=getchar(); }
	while(ch>=‘0‘&&ch<=‘9‘) s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
	return s*w;
}
int n,type;
vector<int> a,Ans;
int rev[N],r[24][2],iiv[N+5];
inline int ksc(int x,int p) { int res=1; for(;p;p>>=1, x=1ll*x*x%Mod) if(p&1) res=1ll*res*x%Mod; return res; }
inline void Get_Rev(int T) { for(ri int i=0;i<T;i++) rev[i]=(rev[i>>1]>>1)|((i&1)?(T>>1):0); }
inline void DFT(int T,vector<int> &s,int type)
{
	for(ri int i=0;i<T;i++) if(rev[i]<i) swap(s[i],s[rev[i]]);
	for(ri int i=2,cnt=1;i<=T;i<<=1,cnt++)
	{
		int wn=r[cnt][type];
		for(ri int j=0,mid=(i>>1);j<T;j+=i)
		{
			for(ri int k=0,w=1;k<mid;k++,w=1ll*w*wn%Mod)
			{
				int x=s[j+k], y=1ll*w*s[j+mid+k]%Mod;
				s[j+k]=(x+y)%Mod;
				s[j+mid+k]=x-y;
				if(s[j+mid+k]<0) s[j+mid+k]+=Mod;
			}
		}
	}
	if(!type) for(ri int i=0,inv=ksc(T,Mod-2);i<T;i++) s[i]=1ll*s[i]*inv%Mod;
}
inline void NTT(int n,int m,vector<int> &A,vector<int> B)
{
	int len=n+m;
	int T=1;
	while(T<=len) T<<=1;
	Get_Rev(T);
	A.resize(T), B.resize(T);
	for(ri int i=n+1;i<T;i++) A[i]=0;
	for(ri int i=m+1;i<T;i++) B[i]=0;
	DFT(T,A,1), DFT(T,B,1);
	for(ri int i=0;i<T;i++) A[i]=1ll*A[i]*B[i]%Mod;
	DFT(T,A,0);
}
void GetInv(int n,vector<int> &F,vector<int> G)
{
	if(n==1) { F[0]=ksc(G[0],Mod-2); return; }
	GetInv((n+1)/2,F,G);
	vector<int> A,B;
	int T=1;
	while(T<=n+n) T<<=1;
	Get_Rev(T);
	A.resize(T), B.resize(T);
	for(ri int i=0;i<n;i++) A[i]=F[i], B[i]=G[i];
	DFT(T,A,1), DFT(T,B,1);
	for(ri int i=0;i<T;i++) A[i]=(2ll*A[i]%Mod-1ll*B[i]*A[i]%Mod*A[i]%Mod+Mod)%Mod;
	DFT(T,A,0);
	for(ri int i=0;i<n;i++) F[i]=A[i];
}
inline void GetDao(int n,vector<int> &A,vector<int> B)
{
	for(ri int i=0;i<n-1;i++) A[i]=1ll*(i+1)*B[i+1]%Mod;
	A[n-1]=0;
}
inline void GetJi(int n,vector<int> &A,vector<int> B)
{
	for(ri int i=1;i<n;i++) A[i]=1ll*B[i-1]*iiv[i]%Mod;
	A[0]=0;
}
struct Node { int x,y; }; int I2;
inline Node operator * (Node a,Node b)
{
	int w1=(1ll*a.x*b.x%Mod+1ll*a.y*b.y%Mod*I2%Mod)%Mod;
	int w2=(1ll*a.x*b.y%Mod+1ll*a.y*b.x%Mod)%Mod;
	return (Node){w1,w2};
}
inline bool Check(int x)
{
	return ksc(x,(Mod-1)/2)==1;
}
inline int Rand()
{
	int w=1ll*rand()*rand()%Mod;
	w+=rand()-rand();
	w=(w%Mod+Mod)%Mod;
	return w;
}
inline Node KSC(Node x,int p) { Node res=(Node){1,0}; for(;p;p>>=1, x=x*x) if(p&1) res=res*x; return res; }
inline int Cipolla(int n)
{
	if(!n) return 0;
	int a=0;
	while(Check((1ll*a*a%Mod-n+Mod)%Mod)) a=Rand();
	I2=(1ll*a*a%Mod-n+Mod)%Mod;
	int X1=KSC((Node){a,1},(Mod+1)/2).x;
	return min(X1,Mod-X1);
}
void Getsqrt(int n,vector<int> &F,vector<int> G)
{
	if(n==1) { F[0]=Cipolla(G[0]); return; }
	Getsqrt((n+1)/2,F,G);
	vector<int> A,B;
	A.resize(n), B.resize(n);
	GetInv(n,A,F);
	for(ri int i=0;i<n;i++) B[i]=G[i];
	NTT(n,n,A,B);
	for(ri int i=0,inv2=(Mod+1)/2;i<n;i++) F[i]=1ll*(F[i]+A[i])*inv2%Mod;
}
inline void GetArcsin(int n,vector<int> &F,vector<int> G)
{
	vector<int> a,b;
	a.resize(n), b.resize(n);
	GetDao(n,a,G);
	for(ri int i=0;i<n;i++) b[i]=G[i];
	NTT(n,n,b,b);
	for(ri int i=0;i<n;i++) b[i]=Mod-b[i]; b[0]++, b[0]%=Mod;
	vector<int> c; c.resize(n);
	Getsqrt(n,c,b);
	for(ri int i=0;i<n;i++) b[i]=0;
	GetInv(n,b,c);
	NTT(n,n,a,b);
	GetJi(n,F,a);
}
inline void GetArctan(int n,vector<int> &F,vector<int> G)
{
	vector<int> a,b;
	a.resize(n), b.resize(n);
	GetDao(n,a,G);
	for(ri int i=0;i<n;i++) b[i]=G[i];
	NTT(n,n,b,b); b[0]++, b[0]%=Mod;
	vector<int> c; c.resize(n);
	GetInv(n,c,b);
	NTT(n,n,a,c);
	GetJi(n,F,a);
}
signed main()
{
	iiv[1]=1;
	for(ri int i=2;i<=N;i++) iiv[i]=1ll*(Mod-Mod/i)*iiv[Mod%i]%Mod;
	r[23][1]=ksc(3,119), r[23][0]=ksc(ksc(3,Mod-2),119);
	for(ri int i=22;~i;i--) r[i][0]=1ll*r[i+1][0]*r[i+1][0]%Mod, r[i][1]=1ll*r[i+1][1]*r[i+1][1]%Mod;
	n=read(), type=read();
	a.resize(n), Ans.resize(n);
	for(ri int i=0;i<n;i++) a[i]=read();
	if(!type) GetArcsin(n,Ans,a);
	else GetArctan(n,Ans,a);
	for(ri int i=0;i<n;i++) printf("%d ",Ans[i]);
	puts("");
	return 0;
}

多项式反三角函数

标签:三角函数   多项式   bit   ==   ref   函数   gis   bool   tin   

原文地址:https://www.cnblogs.com/zkdxl/p/14686126.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!