HDU 4656 Evaluation(MTT)
题意
\(x_k=bc^{2k}+d\)
\(\displaystyle F(x)=\sum_{i=0}^{n-1}a_ix^i\)
给定 \(\{a\},b,c,d,n\) ,求 \(F(x_0),F(x_1),\cdots,F(x_{n-1})\)
思路
设 \(ans_k=F(x_k)\)
\]
二项展开得
\]
设 \(\displaystyle f(i)=a_id^ii!,g(j)={b^j\over {d^jj!}}\)
ans_k=\sum_{j=0}^{n-1}g(j)c^{2kj}\sum_{i=j}^{n-1}f(i){1\over(i-j)!}
\]
不难发现,后面那个 $ \sum$ 与 \(k\) 无关,可以预处理出来。
我们设 \(\displaystyle h(j)=\sum_{i=j}^{n-1}f(i){1\over(i-j)!}\)
这个可以直接用多项式乘出来。
有能力 $ O(1)$ 求解 $ h(j)$ 后,得到
ans_k=\sum_{j=0}^{n-1}g(j)h(j)c^{j^2+k^2-(k-j)^2}\\
ans_k=\sum_{j=0}^{n-1}g(j)h(j){c^{j^2}c^{k^2}\over {c^{{(k-j)}^2}}}\\
ans_k=c^{k^2}\sum_{j=0}^{n-1}g(j)h(j)c^{j^2}{1\over {c^{{(k-j)}^2}}}\\
\]
再进行一次多项式乘法就可以了。
代码
#include<bits/stdc++.h>
#define FOR(i,x,y) for(int i=(x),i##END=(y);i<=i##END;++i)
#define DOR(i,x,y) for(int i=(x),i##END=(y);i>=i##END;--i)
typedef long long ll;
using namespace std;
const double PI=acos(-1.0);
const int N=1<<18|5;
const int P=1e6+3;
namespace _Maths
{
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void exgcd(ll a,ll b,ll &x,ll &y)
{
if(!b){x=1,y=0;return;}
exgcd(b,a%b,y,x);y-=a/b*x;
}
ll Pow(ll a,ll p,ll P)
{
ll res=1;
for(;p>0;(a*=a)%=P,p>>=1)if(p&1)(res*=a)%=P;
return res;
}
ll inv(ll a,ll P){ll x,y;exgcd(a,P,x,y);return (x%P+P)%P;}
};
using namespace _Maths;
struct Complex
{
double x,y;
Complex operator +(const Complex &_)const{return (Complex){x+_.x,y+_.y};}
Complex operator -(const Complex &_)const{return (Complex){x-_.x,y-_.y};}
Complex operator *(const Complex &_)const{return (Complex){x*_.x-y*_.y,x*_.y+y*_.x};}
Complex operator /(const int &_)const{return (Complex){x/_,y/_};}
};
namespace _Polynomial
{
const int K=(1<<15)-1,L=15;
Complex A[N<<1],B[N<<1],C[N<<1],D[N<<1];
Complex w[N<<1];int r[N<<1];
void DFT(Complex *a,int op,int n)
{
FOR(i,0,n-1)if(i<r[i])swap(a[i],a[r[i]]);
for(int i=2;i<=n;i<<=1)
for(int j=0;j<n;j+=i)
for(int k=0;k<i/2;k++)
{
Complex u=a[j+k],t=w[(op==1?n/i*k:n-n/i*k)&(n-1)]*a[j+k+i/2];
a[j+k]=u+t,a[j+k+i/2]=u-t;
}
if(op==-1)FOR(i,0,n-1)a[i]=a[i]/n;
}
void multiply(const int *a,const int *b,int *c,int n1,int n2)
{
int n=1;
while(n<n1+n2-1)n<<=1;
FOR(i,0,n1-1)A[i].x=a[i]&K,A[i].y=a[i]>>L;
FOR(i,0,n2-1)B[i].x=b[i]&K,B[i].y=b[i]>>L;
FOR(i,n1,n-1)A[i].x=A[i].y=0;
FOR(i,n2,n-1)B[i].x=B[i].y=0;
FOR(i,0,n-1)r[i]=(r[i>>1]>>1)|((i&1)*(n>>1));
FOR(i,0,n-1)w[i]=(Complex){cos(2*PI*i/n),sin(2*PI*i/n)};
DFT(A,1,n),DFT(B,1,n);
FOR(i,0,n-1)
{
int j=(n-i)&(n-1);
C[i]=(Complex){0.5*(A[i].x+A[j].x),0.5*(A[i].y-A[j].y)}*B[i];
D[i]=(Complex){0.5*(A[i].y+A[j].y),0.5*(A[j].x-A[i].x)}*B[i];
}
DFT(C,-1,n),DFT(D,-1,n);
FOR(i,0,n-1)
{
ll s=C[i].x+0.5,t=C[i].y+0.5,u=D[i].x+0.5,v=D[i].y+0.5;
c[i]=(s%P+((t+u)%P<<L)+(v%P<<L<<L))%P;
}
}
};
int fac[N],ifac[N],h[N];
int A[N],B[N],C[N<<1];
int a[N],b,c,d;
int n;
ll f(int i){return (ll)a[i]*Pow(d,i,P)%P*fac[i]%P;}
ll g(int i){return (ll)Pow(b,i,P)*inv(Pow(d,i,P)%P*fac[i]%P,P)%P;}
int main()
{
fac[0]=fac[1]=1;FOR(i,2,N-1)fac[i]=(ll)fac[i-1]*i%P;
ifac[0]=ifac[1]=1;FOR(i,2,N-1)ifac[i]=(ll)(P-P/i)*ifac[P%i]%P;
FOR(i,2,N-1)ifac[i]=(ll)ifac[i-1]*ifac[i]%P;
scanf("%d%d%d%d",&n,&b,&c,&d);
FOR(i,0,n-1)scanf("%d",&a[i]);
FOR(i,0,n-1)A[i]=f(i);
FOR(i,1-n,0)B[(n-1)+i]=ifac[-i];
_Polynomial::multiply(A,B,C,n,n);
FOR(i,0,n-1)h[i]=C[(n-1)+i];
FOR(i,0,n-1)A[i]=g(i)*h[i]%P*Pow(c,(ll)i*i,P)%P;
FOR(i,1-n,n-1)B[(n-1)+i]=inv(Pow(c,(ll)i*i,P),P);
_Polynomial::multiply(A,B,C,n,2*n-1);
FOR(i,0,n-1)printf("%lld\n",Pow(c,(ll)i*i,P)*C[(n-1)+i]%P);
return 0;
}
HDU 4656 Evaluation(MTT)的更多相关文章
- HDU 5934 Bomb(炸弹)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 5734 Acperience(返虚入浑)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 5724 Chess(国际象棋)
HDU 5724 Chess(国际象棋) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- HDU 5826 physics(物理)
physics(物理) Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) D ...
- HDU 5835 Danganronpa(弹丸论破)
Danganronpa(弹丸论破) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- hdu 4656 Evaluation [任意模数fft trick]
hdu 4656 Evaluation 题意:给出\(n,b,c,d,f(x) = \sum_{i=1}^{n-1} a_ix^i\),求\(f(b\cdot c^{2k}+d):0\le k < ...
- HDU 3085 Nightmare Ⅱ(噩梦 Ⅱ)
HDU 3085 Nightmare Ⅱ(噩梦 Ⅱ) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- HDU 5976 Detachment(拆分)
HDU 5976 Detachment(拆分) 00 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem D ...
- HDU 4816 Bathysphere(数学)(2013 Asia Regional Changchun)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 Problem Description The Bathysphere is a spheric ...
随机推荐
- Robot framework selenium driver download
Chrome: https://sites.google.com/a/chromium.org/chromedriver/downloads http://npm.taobao.org/mirrors ...
- CSS选择符-----伪类选择符
Element:hover E:hover { sRules } 设置元素在其鼠标悬停时的样式 <!DOCTYPE html> <html> <head> < ...
- MVC中修改Table值
记录下: 遇到这样一个问题,表中有一个Char栏位,为1/0 ,只是在视图界面 让其显示为 开始/结束, 目前想到的两种解决办法: ①后台写查询的SQL时,直接写 SELECT a.Status, ( ...
- Spark学习之路 (四)Spark的广播变量和累加器
一.概述 在spark程序中,当一个传递给Spark操作(例如map和reduce)的函数在远程节点上面运行时,Spark操作实际上操作的是这个函数所用变量的一个独立副本.这些变量会被复制到每台机器上 ...
- 特征点方法 - Harris和SURF的手工实现
整理去年做的小项目,纪念我的图像处理入门. 因为要在DSP上实现,所以完全手工C代码垒起来的,还要保证和PC端跑的结果一样,觉得可能特殊场景会有用,上传github,没有依赖任何库: 格式注释什么的暂 ...
- redis 缓存刷新
- 把object转成JSONObject JSON.toJSON
把object转成JSONObject JSON.toJSON public void onNext(Object o) { LogUtil.i("getFavorites", & ...
- hashCode 一致性hash 算法
1 如果两个对象相同,那么它们的hashCode值一定要相同.也告诉我们重写equals方法,一定要重写 hashCode方法,同一个对象那么hashcode就是同一个(同一个对象什么都是相同的).2 ...
- tensorflow serving
1.安装tensorflow serving 1.1确保当前环境已经安装并可运行tensorflow 从github上下载源码 git clone --recurse-submodules https ...
- The Little Prince-12/03
The Little Prince-12/03 These days, I am always busy with my things, including experiment and others ...