HDU 6061 RXD and functions NTT
RXD and functions
RXD has a transformation of function Tr(f,a), it returns another function g, which has a property that g(x)=f(x−a).
Given a1,a2,a3,…,am, RXD generates a polynomial function sequence gi, in which g0=f and gi=Tr(gi−1,ai)
RXD wants you to find gm, in the form of ∑mi=0bixi
You need to output bi module 998244353.
n≤105
For each test case, the first line consists of 1 integer n, which means degF.
The next line consists of n+1 intergers ci,0≤ci<998244353, which means the coefficient of the polynomial.
The next line contains an integer m, which means the length of a.
The next line contains m integers, the i - th integer is ai.
There are 11 test cases.
0<=ai<998244353
∑m≤105
0 0 1
1
1
$(x - 1) ^ 2 = x^2 - 2x + 1$
题解:

代码:
#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
typedef unsigned long long ULL;
const long long INF = 1e18+1LL;
const double pi = acos(-1.0);
const int N = 5e5+, M = 1e3+,inf = 2e9; const long long P=998244353LL,mod = 998244353LL;
const LL G=3LL; LL mul(LL x,LL y){
return (x*y-(LL)(x/(long double)P*y+1e-)*P+P)%P;
}
LL qpow(LL x,LL k){
LL ret=;
while(k){
if(k&) ret=mul(ret,x);
k>>=;
x=mul(x,x);
}
return ret;
}
LL wn[];
void getwn(){
for(int i=; i<=; ++i){
int t=<<i;
wn[i]=qpow(G,(P-)/t);
}
} int len;
void NTT(LL y[],int op){
for(int i=,j=len>>,k; i<len-; ++i){
if(i<j) swap(y[i],y[j]);
k=len>>;
while(j>=k){
j-=k;
k>>=;
}
if(j<k) j+=k;
}
int id=;
for(int h=; h<=len; h<<=) {
++id;
for(int i=; i<len; i+=h){
LL w=;
for(int j=i; j<i+(h>>); ++j){
LL u=y[j],t=mul(y[j+h/],w);
y[j]=u+t;
if(y[j]>=P) y[j]-=P;
y[j+h/]=u-t+P;
if(y[j+h/]>=P) y[j+h/]-=P;
w=mul(w,wn[id]);
}
}
}
if(op==-){
for(int i=; i<len/; ++i) swap(y[i],y[len-i]);
LL inv=qpow(len,P-);
for(int i=; i<len; ++i) y[i]=mul(y[i],inv);
}
}
LL c[N],fac[N],ans[N],inv[N],id[N],s[N],t[N];
int n;
void solve(LL mo) {
if(mo == ) {
for(int i = ; i <= n; ++i)
ans[i] = c[i];
return ;
}
mo = (mod - mo) % mod;
len = ;
while(len <= *n+) len<<=;
id[] = ;
for(int i = ; i <= n; ++i)
id[i] = id[i-] * mo % mod;
for(int i = ; i < len ; ++i) s[i] = ,t[i] = ;
for(int i = ; i <= n; ++i)
s[i] = c[i]*fac[i]%mod,
t[n - i] = id[i] * inv[i] % mod;
NTT(s,),NTT(t,);
for(int i = ; i < len; ++i) s[i] = s[i]*t[i] % mod;
NTT(s,-);
for(int i = ; i <= n; ++i) {
ans[i] = s[n+i]*inv[i] % mod;
}
}
int m;
int main() {
getwn();
while(scanf("%d",&n)!=EOF) {
for(int i = ; i <= n; ++i) {
scanf("%lld",&c[i]);
}
fac[] = ;
for(int i = ; i <= n; ++i) {
fac[i] = fac[i-]*1LL*i%mod;
}
inv[n]=qpow(fac[n],mod-);
for(int i = n-; i >= ; --i)
inv[i]=inv[i+]*1ll*(i+)%mod;
scanf("%d",&m);
int sum = ;
for(int i = ; i <= m; ++i) {
int x;
scanf("%d",&x);
sum += x;
sum %= mod;
}
solve(sum);
for(int i = ; i < n; ++i)
printf("%lld ",ans[i]);
printf("%lld \n",ans[n]);
}
return ;
}
HDU 6061 RXD and functions NTT的更多相关文章
- 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\) 函数解析式的各项系数,对 ...
- HDU 6061 RXD and functions
题目链接:HDU-6061 题意:给定f(x),求f(x-A)各项系数. 思路:推导公式有如下结论: 然后用NTT解决即可. 代码: #include <set> #include < ...
- HDU6061 RXD and functions【NTT】
\(RXD\ and\ functions\) Problem Description RXD has a polynomial function \(f(x)\), \(f(x)=\sum ^{n} ...
- HDU 6060 - RXD and dividing | 2017 Multi-University Training Contest 3
/* HDU 6060 - RXD and dividing [ 分析,图论 ] | 2017 Multi-University Training Contest 3 题意: 给一个 n 个节点的树, ...
- HDU 6063 - RXD and math | 2017 Multi-University Training Contest 3
比赛时候面向过题队伍数目 打表- - 看了题解发现确实是这么回事,分析能力太差.. /* HDU 6063 - RXD and math [ 数学,规律 ] | 2017 Multi-Universi ...
- HDU 6061 推导 NTT
复函数,递归代入,可以得到最终的式子为$f(x-\sum_{i=1}^{m}{a_i})$,且$f(x) = \sum_{i = 0}^{n}{c_ix^i}$,求最终各个x项的系数. 设$S=\su ...
- 【推导】【NTT】hdu6061 RXD and functions(NTT)
题意:给定一个n次多项式f(x)的各项系数,让你求f(x-Σai)的各项系数. http://blog.csdn.net/v5zsq/article/details/76780053 推导才是最关键的 ...
随机推荐
- java中传入一个数或字符串或数组进行反转
//将一个数用递归反转--利用余数 public static void inverse(int n) { System.out.print(n % 10); if (n >= 10) inve ...
- Android自制rom,为update.zip签名
确认已经安装好openssl openssl genrsa -out key.pem openssl req -new -key key.pem -out request.pem openssl x5 ...
- BZOJ 2820 YY的GCD ——莫比乌斯反演
我们可以枚举每一个质数,那么答案就是 $\sum_{p}\sum_{d<=n}\mu(d)*\lfloor n / pd \rfloor *\lfloor m / pd \rfloor$ 直接做 ...
- 【BZOJ1500】维修数列(splay)
题意: 输入的第1 行包含两个数N 和M(M ≤20 000),N 表示初始时数列中数的个数,M表示要进行的操作数目.第2行包含N个数字,描述初始时的数列.以下M行,每行一条命令,格式参见问题描述中的 ...
- Linux 环境下思源黑体字体与 Java 之间的兼容性问题的解决(补充说明)
在前一篇随笔中,我讲了一下有关 Linux 环境下思源黑体与 Java 之间的兼容性问题,后来经过测试发现,默认安装的思源黑体字体同时包含简体字体和繁体字体,并且其对应的语言编码也是不同的.尝试着把繁 ...
- codeforces Gym 101572 I 有向图最小环路径
题目链接 http://codeforces.com/gym/101572 题意 一共n个文件 存在依赖关系 根据给出的依赖关系 判断是否存在循环依赖 ,不存在的话输出SHIP IT,存在的话 ...
- Codeforces 486D Valid Sets (树型DP)
题目链接 Valid Sets 题目要求我们在一棵树上计符合条件的连通块的个数. 满足该连通块内,点的权值极差小于等于d 树的点数满足 n <= 2000 首先我们先不管这个限制条件,也就是先考 ...
- P2136 拉近距离(spfa判负环)
洛谷—— P2136 拉近距离 题目背景 我是源点,你是终点.我们之间有负权环. ——小明 题目描述 在小明和小红的生活中,有N个关键的节点.有M个事件,记为一个三元组(Si,Ti,Wi),表示从节点 ...
- pyserial安装
参考网址:pyserial.sourceforge.net/pyserial.html#installation Download the archive from http://pypi.pytho ...
- luogu P1342 请柬
题目描述 在电视时代,没有多少人观看戏剧表演.Malidinesia古董喜剧演员意识到这一事实,他们想宣传剧院,尤其是古色古香的喜剧片.他们已经打印请帖和所有必要的信息和计划.许多学生被雇来分发这些请 ...