【推导】【NTT】hdu6061 RXD and functions(NTT)
题意:给定一个n次多项式f(x)的各项系数,让你求f(x-Σai)的各项系数。
http://blog.csdn.net/v5zsq/article/details/76780053
推导才是最关键的部分……我的数学推导能力很弱,比赛的时候很难推出来……尤其是累加变量交换顺序、换元这两个常用的技巧在配凑卷积形式以及莫比乌斯反演中都很常用
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
#define N ((1<<18)+5)
#define MOD 998244353ll
ll Quick_Pow(ll a,ll p){
if(p==0){
return 1ll;
}
ll res=Quick_Pow(a,p>>1);
res=res*res%MOD;
if((p&1ll)==1ll){
res=(a%MOD*res)%MOD;
}
return res;
}
struct NTT{
int n,rev[N];
ll g;
void ini(int lim) {
g=3;//1004535809,998244353的原根都是3
n=1;
int k=0;
while(n<lim){
n<<=1;
++k;
}
for(int i=0;i<n;++i){
rev[i]=((rev[i>>1]>>1)|((i&1)<<(k-1)));
}
}
void dft(ll a[],int DFT) {
for(int i=0;i<n;++i){
if(i<rev[i]){
swap(a[i],a[rev[i]]);
}
}
for(int l=2;l<=n;l<<=1){
int m=l>>1;
ll wn=Quick_Pow(g,DFT==1 ? (MOD-1ll)/(ll)l : MOD-1ll-(MOD-1ll)/(ll)l);
for(int i=0;i<n;i+=l){
ll w=1;
for(int k=0;k<m;++k){
ll t=w*a[i+k+m]%MOD;
a[i+k+m]=(a[i+k]-t+MOD)%MOD;
a[i+k]=(a[i+k]+t)%MOD;
w=w*wn%MOD;
}
}
}
if(DFT==-1){
ll inv=Quick_Pow(n,MOD-2ll);
for(int i=0;i<n;++i){
a[i]=a[i]*inv%MOD;
}
}
}
void mul(ll a[],ll b[],int len) {
ini(len);
dft(a,1);
dft(b,1);
for(int i=0;i<n;++i){
a[i]=a[i]*b[i];
}
dft(a,-1);
}
}ntt;
ll c[N],A[N],B[N],jc[N],jcni[N];
int n,m;
int main(){
jc[0]=1;
jcni[0]=1;
for(int i=1;i<=100000;++i){
jc[i]=(jc[i-1]*(ll)i)%MOD;
jcni[i]=Quick_Pow(jc[i],MOD-2ll);
}
ll x;
// freopen("hdu6061.in","r",stdin);
while(scanf("%d",&n)!=EOF){
memset(A,0,sizeof(A));
memset(B,0,sizeof(B));
for(int i=0;i<=n;++i){
scanf("%lld",&c[i]);
}
ll a=0;
scanf("%d",&m);
for(int i=1;i<=m;++i){
scanf("%lld",&x);
a=(a+x)%MOD;
}
ll pw=1;
for(int i=0;i<=n;++i){
A[i]=(c[n-i]*jc[n-i])%MOD;
B[i]=(pw*jcni[i])%MOD;
pw=(pw*(MOD-a))%MOD;
}
ntt.mul(A,B,n*2+1);
for(int i=0;i<=n;++i){
printf("%lld ",(A[n-i]*jcni[i])%MOD);
}
puts("");
}
return 0;
}
【推导】【NTT】hdu6061 RXD and functions(NTT)的更多相关文章
- HDU6061 RXD and functions【NTT】
\(RXD\ and\ functions\) Problem Description RXD has a polynomial function \(f(x)\), \(f(x)=\sum ^{n} ...
- HDU 6061 RXD and functions NTT
RXD and functions Problem Description RXD has a polynomial function f(x), f(x)=∑ni=0cixiRXD has a tr ...
- HDU 6061 - RXD and functions | 2017 Multi-University Training Contest 3
每次NTT都忘记初始化,真的是写一个小时,Debug两个小时- - /* HDU 6061 - RXD and functions [ NTT ] | 2017 Multi-University Tr ...
- 2017 多校3 hdu 6061 RXD and functions
2017 多校3 hdu 6061 RXD and functions(FFT) 题意: 给一个函数\(f(x)=\sum_{i=0}^{n}c_i \cdot x^{i}\) 求\(g(x) = f ...
- HDU 6061 RXD and functions(NTT)
题意 给定一个\(n\) 次的 \(f\) 函数,向右移动 \(m\) 次得到 \(g\) 函数,第 \(i\) 次移动长度是 \(a_i\) ,求 \(g\) 函数解析式的各项系数,对 ...
- 2017 Multi-University Training Contest - Team 3 RXD and functions(NTT)
题解: 我是参考的 http://blog.csdn.net/qq_32570675/article/details/76571666 这一篇 orz 原来可以这么变换,涨姿势 代码: #includ ...
- HDU 6061 RXD and functions
题目链接:HDU-6061 题意:给定f(x),求f(x-A)各项系数. 思路:推导公式有如下结论: 然后用NTT解决即可. 代码: #include <set> #include < ...
- 【Tarjan】【LCA】【动态规划】【推导】hdu6065 RXD, tree and sequence
划分出来的每个区间的答案,其实就是连续两个的lca的最小值. 即5 2 3 4 这个区间的答案是min(dep(lca(5,2)),dep(lca(2,3),dep(lca(3,4)))). 于是dp ...
- hdu6061[NTT推公式] 2017多校3
/*hdu6061[NTT推公式] 2017多校3*/ #include <bits/stdc++.h> using namespace std; typedef long long LL ...
随机推荐
- SQL Server Delete Duplicate Rows
There can be two types of duplication of rows in a table 1. Entire row getting duplicated because th ...
- ubuntu下调整cpu频率
环境:ubuntu15.10 查看内核支持的cpu策略 cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors 比如我 ...
- PHP序列化、反序列化常用的魔术方法
__wakeup() //使用unserialize时触发__sleep() //使用serialize时触发__destruct() //对象被销毁时触发__call() //在对象上下文中调用不可 ...
- linux安装lamp
github https://github.com/zblogcn/zblogphp Installation If your server system: CentOS yum -y install ...
- mysql之基本数据库操作(二)
环境信息 数据库:mysql-5.7.20 操作系统:Ubuntu-16.04.3 mysql的启动.退出.重启 # 启动 $ sudo service mysqld start # 停止 $ sud ...
- Open Compute Project
Open Compute Project https://github.com/opencomputeproject https://github.com/floodlight/floodlight ...
- 使用UpdatePanel时FileUpload失效的问题
出处:http://www.cnblogs.com/caicainiao/archive/2010/12/08/1900377.html 1.使用UpdatePanel后,FileUpload的Has ...
- TensorFlow计算模型—计算图
TensorFlow是一个通过计算图的形式来表述计算的编程系统.其中的Tnesor,代表它的数据结构,而Flow代表它的计算模型.TensorFlow中的每一个计算都是计算图上的一个节点,而节点之间的 ...
- spring restTemplate 用法
发出get请求,方式一 String url = serverUrl+"/path/path?id={id}"; int i = restTemplate.getForObject ...
- 【python】r+,w+ 全局变量
来源:http://www.educity.cn/wenda/352188.html r+:可读可写,若文件不存在,报错w+: 可读可写,若文件不存在,创建文本模式:遇换行符时根据操作系统不同自动转换 ...