[xsy1140]求值

Posted jefflyy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[xsy1140]求值相关的知识,希望对你有一定的参考价值。

$ ewcommand{ali}[1]{egin{align*}#1end{align*}}$题意:给定$n,b,c,d,e,a_{0cdots n-1}$,令$x_k=bc^{4k}+dc^{2k}+e$,$f(x)=sumlimits_{i=0}^{n-1}a_ix^i$,求$f(x_{0cdots n-1})$

如果单纯看推公式的话,这题没什么思维含量,但对各种卷积的处理还是需要一定的思考的

1.$c=0$,此时$x_0=b+d+e$,$x_{1cdots n-1}=e$,直接算即可

2.$b=0$,我们来推导一番

$ali{f(x_k)&=sumlimits_{i=0}^{n-1}a_i(dc^{2k}+e)^i\&=sumlimits_{i=0}^{n-1}a_isumlimits_{j=0}^iinom ijd^jc^{2kj}e^{i-j}\&=sumlimits_{j=0}^{n-1}dfrac{d^jc^{2kj}}{j!}sumlimits_{i=j}^{n-1}dfrac{a_ii!e^{i-j}}{(i-j)!}}$

令$p_j=sumlimits_{i=j}^{n-1}frac{a_ii!e^{i-j}}{(i-j)!}$,这是$a_ii!(i=n-1cdots0)$卷$frac{e^i}{i!}(i=0cdots n-1)$的$n-1-j$项

$ali{sumlimits_{j=0}^{n-1}dfrac{d^jc^{2kj}p_j}{j!}&=c^{k^2}sumlimits_{j=0}^{n-1}dfrac{c^{-(k-j)^2}c^{j^2}d^jp_j}{j!}\&=c^{k^2}left(sumlimits_{j=0}^kdfrac{c^{-(k-j)^2}c^{j^2}d^jp_j}{j!}+sumlimits_{j=k+1}^{n-1}dfrac{c^{-(j-k)^2}c^{j^2}d^jp_j}{j!} ight)}$

第一个sigma是$c^{-i^2}(i=0cdots n-1)$卷$frac{c^{i^2}d^ip_i}{i!}(i=0cdots n-1)$的$k$项,第二个sigma是$frac{c^{i^2}d^ip_i}{i!}(i=n-1cdots1)$卷$c^{-i^2}(i=1cdots n-1)$的$n-2-k$项

3.一般情况

我们先配方,$bc^{4k}+dc^{2k}+e=bleft(c^{2k}+frac d{2b} ight)^2+e-frac{d^2}{4b}$,重新定义$d=frac d{2b},e=e-frac{d^2}{4b}$,于是$x_k=b(c^{2k}+d)^2+e$

$ali{f(x_k)&=sumlimits_{i=0}^{n-1}a_ileft[bleft(c^{2k}+d ight)^2+e ight]^2\&=sumlimits_{i=0}^{n-1}a_isumlimits_{j=i}^{n-1}inom ijb^jleft(c^{2k}+d ight)^{2j}e^{i-j}\&=sumlimits_{j=0}^{n-1}dfrac{b^jleft(c^{2k}+d ight)^{2j}p_j}{j!}\&=sumlimits_{j=0}^{n-1}dfrac{b^jp_j}{j!}sumlimits_{l=0}^{2j}inom{2j}lc^{2kl}d^{2j-l}\&=sumlimits_{l=0}^{2n-2}dfrac{c^{2kl}}{l!}sumlimits_{j=leftlceilfrac l2 ight ceil}^{n-1}dfrac{(2j)!d^{2j-l}b^jp_j}{j!(2j-l)!}}$

令$q_l=sumlimits_{j=leftlceilfrac l2 ight ceil}^{n-1}frac{(2j)!d^{2j-l}b^jp_j}{j!(2j-l)!}$,下面分别对$l$为奇数和偶数的情况分开讨论,因为式子中偏移$-l$的项含$2j$,所以推式子的时候要适当换元$t=2j$

$l$为奇数,是$frac{(2i)!b^ip_i}{i!}(i=n-1cdots1)$卷$frac{d^{2i-1}}{(2i-1)!}(i=1cdots n-1)$的$n-1-frac{l+1}2$项

$l$为偶数,是$frac{(2i)!b^ip_i}{i!}(i=n-1cdots0)$卷$frac{d^{2i}}{(2i)!}(i=0cdots n-1)$的$n-1-frac l2$项

$ali{sumlimits_{l=0}^{2n-2}dfrac{c^{2kl}q_l}{l!}&=c^{k^2}sumlimits_{l=0}^{2n-2}dfrac{c^{-(k-l)^2}c^{l^2}q_l}{l!}\&=c^{k^2}left(sumlimits_{l=0}^kdfrac{c^{-(k-l)^2}c^{l^2}q_l}{l!}+sumlimits_{l=k+1}^{2n-2}dfrac{c^{-(l-k)^2}c^{l^2}q_l}{l!} ight)}$

第一个sigma是$c^{-i^2}(i=0cdots n-1)$卷$frac{c^{i^2}q_i}{i!}(i=0cdots n-1)$的$k$项,第二个sigma是$frac{c^{i^2}q_i}{i!}(i=2n-2cdots1)$卷$c^{-i^2}(i=1cdots2n-2)$的$2n-3-k$项

然后就做完了,感觉略毒...

#include<stdio.h>
#include<string.h>
#include<math.h>
typedef long long ll;
const int mod=1000003,maxn=524288;
typedef double du;
int mul(int a,int b){return a*(ll)b%mod;}
int ad(int a,int b){return(a+b)%mod;}
int de(int a,int b){return(a-b)%mod;}
int pow(int a,ll b){
	int s=1;
	while(b){
		if(b&1)s=mul(s,a);
		a=mul(a,a);
		b>>=1;
	}
	return s;
}
struct complex{
	du x,y;
	complex(du a=0,du b=0){x=a;y=b;}
};
complex operator+(complex a,complex b){return complex(a.x+b.x,a.y+b.y);}
complex operator-(complex a,complex b){return complex(a.x-b.x,a.y-b.y);}
complex operator*(complex a,complex b){return complex(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x);}
void swap(complex&a,complex&b){
	complex c=a;
	a=b;
	b=c;
}
int rev[maxn],N;
complex w[19][maxn];
void pre(int n){
	int i,j,k;
	for(N=1,k=0;N<n;N<<=1)k++;
	for(i=0;i<N;i++)rev[i]=(rev[i>>1]>>1)|((i&1)<<(k-1));
	k=0;
	for(i=2;i<=N;i<<=1){
		for(j=0;j<i;j++)w[k][j]=complex(cos(j*M_PI/(i/2)),sin(j*M_PI/(i/2)));
		k++;
	}
}
void fft(complex*a,int on){
	int i,j,k,f;
	complex t;
	for(i=0;i<N;i++){
		if(i<rev[i])swap(a[i],a[rev[i]]);
	}
	f=0;
	for(i=2;i<=N;i<<=1){
		for(j=0;j<N;j+=i){
			for(k=0;k<i>>1;k++){
				t=w[f][k];
				if(on==-1)t.y=-t.y;
				t=t*a[i/2+j+k];
				a[i/2+j+k]=a[j+k]-t;
				a[j+k]=a[j+k]+t;
			}
		}
		f++;
	}
	if(on==-1){
		for(i=0;i<N;i++)a[i].x/=N;
	}
}
complex A[maxn],B[maxn],C[maxn],D[maxn];
void conv(int*a,int*b,int*c){
	int i;
	complex t;
	for(i=0;i<N;i++){
		A[i]=a[i]>>10;
		B[i]=a[i]&1023;
		C[i]=b[i]>>10;
		D[i]=b[i]&1023;
	}
	fft(A,1);
	fft(B,1);
	fft(C,1);
	fft(D,1);
	for(i=0;i<N;i++){
		t=A[i]*D[i]+B[i]*C[i];
		A[i]=A[i]*C[i];
		C[i]=B[i]*D[i];
		B[i]=t;
	}
	fft(A,-1);
	fft(B,-1);
	fft(C,-1);
	for(i=0;i<N;i++)c[i]=((llround(A[i].x)%mod<<20)+(llround(B[i].x)%mod<<10)+llround(C[i].x)%mod)%mod;
}
int a[maxn],t1[maxn],t2[maxn],t3[maxn],fac[maxn],rfac[maxn],p[maxn],s[maxn],f1[maxn],f2[maxn],n,b,c,d,e;
namespace c0{
	int get(int x){
		int s,t,i;
		s=0;
		t=1;
		for(i=0;i<n;i++){
			s=ad(s,mul(t,a[i]));
			t=mul(t,x);
		}
		return ad(s,mod);
	}
	void solve(){
		int i,s1,s2;
		s1=get(b+d+e);
		s2=get(e);
		printf("%d
",s1);
		for(i=1;i<n;i++)printf("%d
",s2);
	}
}
namespace b0{
	void solve(){
		int i,t,u,v,w;
		t=1;
		for(i=0;i<n;i++){
			t1[n-1-i]=mul(a[i],fac[i]);
			t2[i]=mul(t,rfac[i]);
			t=mul(t,e);
		}
		conv(t1,t2,t3);
		for(i=0;i<n;i++)p[i]=t3[n-1-i];
		memset(t1,0,sizeof(t1));
		memset(t2,0,sizeof(t2));
		t=pow(c,mod-2);
		u=1;
		v=1;
		w=1;
		for(i=0;i<n;i++){
			t1[i]=u;
			t2[i]=mul(mul(v,w),mul(p[i],rfac[i]));
			u=mul(u,pow(t,i*2+1));
			v=mul(v,pow(c,i*2+1));
			w=mul(w,d);
		}
		conv(t1,t2,t3);
		for(i=0;i<n;i++)f1[i]=t3[i];
		memset(t1,0,sizeof(t1));
		memset(t2,0,sizeof(t2));
		u=t;
		v=c;
		w=d;
		for(i=1;i<n;i++){
			t1[n-1-i]=mul(mul(v,w),mul(p[i],rfac[i]));
			t2[i-1]=u;
			u=mul(u,pow(t,i*2+1));
			v=mul(v,pow(c,i*2+1));
			w=mul(w,d);
		}
		conv(t1,t2,t3);
		for(i=0;i<n;i++)f2[i]=t3[n-2-i];
		u=1;
		for(i=0;i<n;i++){
			s[i]=mul(u,ad(f1[i],f2[i]));
			u=mul(u,pow(c,i*2+1));
		}
		for(i=0;i<n;i++)printf("%d
",ad(s[i],mod));
	}
}
namespace def{
	int q[maxn];
	void solve(){
		int i,t,u,v;
		u=mul(d,pow(2*b%mod,mod-2));
		v=de(e,mul(mul(d,d),pow(4*b%mod,mod-2)));
		d=u;
		e=v;
		t=1;
		for(i=0;i<n;i++){
			t1[n-1-i]=mul(a[i],fac[i]);
			t2[i]=mul(t,rfac[i]);
			t=mul(t,e);
		}
		conv(t1,t2,t3);
		for(i=0;i<n;i++)p[i]=t3[n-1-i];
		memset(t1,0,sizeof(t1));
		memset(t2,0,sizeof(t2));
		t=1;
		u=d;
		for(i=1;i<n;i++){
			t=mul(t,b);
			t1[n-1-i]=mul(mul(fac[i*2],mul(t,p[i])),rfac[i]);
			t2[i-1]=mul(u,rfac[2*i-1]);
			u=mul(u,mul(d,d));
		}
		conv(t1,t2,t3);
		for(i=1;i<=2*n-2;i+=2)q[i]=t3[n-1-(i+1)/2];
		memset(t1,0,sizeof(t1));
		memset(t2,0,sizeof(t2));
		t=1;
		u=1;
		for(i=0;i<n;i++){
			t1[n-1-i]=mul(mul(fac[i*2],mul(t,p[i])),rfac[i]);
			t2[i]=mul(u,rfac[2*i]);
			t=mul(t,b);
			u=mul(u,mul(d,d));
		}
		conv(t1,t2,t3);
		for(i=0;i<=2*n-2;i+=2)q[i]=t3[n-1-i/2];
		memset(t1,0,sizeof(t1));
		memset(t2,0,sizeof(t2));
		t=pow(c,mod-2);
		u=1;
		v=1;
		for(i=0;i<n;i++){
			t1[i]=u;
			t2[i]=mul(mul(v,q[i]),rfac[i]);
			u=mul(u,pow(t,i*2+1));
			v=mul(v,pow(c,i*2+1));
		}
		conv(t1,t2,t3);
		for(i=0;i<n;i++)f1[i]=t3[i];
		memset(t1,0,sizeof(t1));
		memset(t2,0,sizeof(t2));
		u=t;
		v=c;
		for(i=1;i<=2*n-2;i++){
			t1[2*n-2-i]=mul(mul(v,q[i]),rfac[i]);
			t2[i-1]=u;
			u=mul(u,pow(t,i*2+1));
			v=mul(v,pow(c,i*2+1));
		}
		pre(n<<2);
		conv(t1,t2,t3);
		for(i=0;i<n;i++)f2[i]=t3[2*n-3-i];
		u=1;
		for(i=0;i<n;i++){
			s[i]=mul(u,ad(f1[i],f2[i]));
			u=mul(u,pow(c,2*i+1));
		}
		for(i=0;i<n;i++)printf("%d
",ad(s[i],mod));
	}
}
int main(){
	int i;
	scanf("%d%d%d%d%d",&n,&b,&c,&d,&e);
	for(i=0;i<n;i++)scanf("%d",a+i);
	pre(n<<1);
	fac[0]=1;
	for(i=1;i<N;i++)fac[i]=mul(fac[i-1],i);
	rfac[N-1]=pow(fac[N-1],mod-2);
	for(i=N-1;i>0;i--)rfac[i-1]=mul(rfac[i],i);
	if(c==0)
		c0::solve();
	else if(b==0)
		b0::solve();
	else
		def::solve();
}

以上是关于[xsy1140]求值的主要内容,如果未能解决你的问题,请参考以下文章

Luogu 1140 相似基因

maven web项目的web.xml报错The markup in the document following the root element must be well-formed.(代码片段

P1140 相似基因

xmlns,xmlns:xsi,xsi:schemaLocation和targetNamespace?

广度优先搜索(BFS)----------------(TjuOj1140_Dungeon Master)

Codeforces 1140F 线段树 分治 并查集