HDU6061 RXD and functions【NTT】
\(RXD\ and\ functions\)
Problem Description
RXD has a polynomial function \(f(x)\), \(f(x)=\sum ^{n}_{i=0}c_ix_i\)
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 \(a_1,a_2,a_3,…,a_m\), RXD generates a polynomial function sequence \(g_i\), in which \(g_0=f\) and \(g_i=Tr(g_{i−1},a_i)\)
RXD wants you to find \(g_m\), in the form of \(\sum ^{m}_{i=0}b_ix_i\)
You need to output bi module \(998244353.\)
\(n≤10^5\)
Input
There are several test cases, please keep reading until EOF.
For each test case, the first line consists of \(1\) integer \(n\), which means \(deg\ F\).
The next line consists of \(n+1\) intergers \(c_i\),\(0 \le 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 \(a_i\).
There are \(11\) test cases.
\(0\le ai<998244353\)
\(\sum m\le10^5\)
Output
For each test case, output an polynomial with degree n, which means the answer.
Sample Input
2
0 0 1
1
1
Sample Output
1 998244351 1
Hint
\((x - 1) ^ 2 = x^2 - 2x + 1\)
题解:
显然最终操作完的式子为\(\sum_{i=0}^{n}c_i(x-\sum_{i-1}^{m}a_i)^i\)
现在我们记\((-\sum_{i=1}^{m}a_i)\%MOD=a\)
然后变成这样:
\(\sum_{i=0}^{n}c_i(x-a)^i\)
接下来我们对式子进行二项式展开:
\(\sum_{i=0}^{n}\sum_{j=i}^{n}C(j,j-i)c_j\cdot a^{j-i}\cdot x^i\)
用\(j=j-i\)替换\(j\):
\(\sum_{i=0}^{n}\sum_{j=0}^{n-i}C(j+i,j)\cdot c_{j+i}\cdot a^j\cdot x^j\)
把组合数展开:
\(\sum_{i=0}^{n}\sum_{j=0}^{n-i}\frac{(i+j)!}{i!\cdot j!}c_{i+j}\cdot a^j\cdot x^j\)
整理一下,把和内层求和无关的提到外面来得到:
\(\sum_{i=0}^{n}\frac{x^i}{i!}\sum_{j=0}^{n-i}c_{i+j}\cdot (i+j)!\cdot\frac{a^j}{j!}\)
现在我们先怎么转化里面的式子,使之变成卷积的形式:
\(\sum_{j=0}^{n-i}c_{i+j}\cdot (i+j)!\cdot\frac{a^j}{j!}\)
用\(j+k=n-i\)来做替换:
\(\Rightarrow \sum_{j+k=n-i} c_{n-k}\cdot (n-k)!\cdot \frac{a^j}{j!}\)
发现这个式子就是卷积的形式了
令\(A[n]=\sum c_{n-i}\cdot (n-i)!\)
\(B[n]=\sum \frac{a^i}{i!}\)
\(NTT\)来搞即可
//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 1e6+7;
using LL = int_fast64_t;
const LL MOD = 998244353;
const LL g = 3;
int n,limit,m,l,r[MAXN];
LL fact[MAXN],rfact[MAXN],c[MAXN],A[MAXN],B[MAXN];
LL qpow(LL a, LL b){
LL ret = 1;
while(b){
if(b&1) ret = ret * a % MOD;
b >>= 1;
a = a * a % MOD;
}
return ret;
}
LL inv(LL x){ return qpow(x,MOD-2); }
void NTT(LL arr[], int rev){
for(int i = 0; i < limit; i++) if(i<r[i]) swap(arr[i],arr[r[i]]);
for(int len = 1; len < limit; len <<= 1){
LL wn = qpow(g,(MOD-1)/(len<<1));
if(rev==-1) wn = inv(wn);
for(int R = 0; R < limit; R += (len<<1)){
LL w = 1;
for(int i = R; i < R + len; i++){
LL x = arr[i];
LL y = w * arr[i+len] % MOD;
arr[i] = (x+y)%MOD;
arr[i+len] = (x-y+MOD)%MOD;
w = w * wn % MOD;
}
}
}
}
void solve(){
LL a = 0;
for(int i = 0; i <= n; i++) scanf("%I64d",&c[i]);
scanf("%d",&m);
for(int i = 1; i <= m; i++){
int x; scanf("%d",&x);
a -= x;
if(a<0) a += MOD;
}
limit = 1, l = 0;
while(limit<=(n<<1)) limit <<= 1, l++;
for(int i = 0; i < limit; i++) r[i] = ((r[i>>1]>>1) | ((i&1)<<(l-1)));
LL powa = 1;
for(int i = 0; i < limit; i++){
if(i<=n){
A[i] = fact[n-i] * c[n-i] % MOD;
B[i] = powa * rfact[i] %MOD;
powa = powa * a % MOD;
}
else A[i] = B[i] = 0;
}
NTT(A,1); NTT(B,1);
for(int i = 0; i < limit; i++) A[i] = A[i] * B[i] % MOD;
NTT(A,-1);
for(int i = 0; i < limit; i++) A[i] = A[i] * inv(limit) % MOD;
for(int i = 0; i <= n; i++) printf("%I64d ",A[n-i]*rfact[i]%MOD); puts("");
}
int main(){
fact[0] = 1; for(int i = 1; i < MAXN; i++) fact[i] = i * fact[i-1] % MOD;
rfact[MAXN-1] = inv(fact[MAXN-1]);
for(int i = MAXN - 2; i >= 0; i--) rfact[i] = rfact[i+1] * (i+1) % MOD;
while(scanf("%d",&n)!=EOF) solve();
return 0;
}
HDU6061 RXD and functions【NTT】的更多相关文章
- 【推导】【NTT】hdu6061 RXD and functions(NTT)
题意:给定一个n次多项式f(x)的各项系数,让你求f(x-Σai)的各项系数. http://blog.csdn.net/v5zsq/article/details/76780053 推导才是最关键的 ...
- 【NTT】loj#6261. 一个人的高三楼
去年看过t老师写这题博客:以为是道神仙题 题目大意 求一个数列的$k$次前缀和.$n\le 10^5$. 题目分析 [计数]cf223C. Partial Sums 加强版.注意到最后的式子是$f_i ...
- POJ 1080 Human Gene Functions 【dp】
题目大意:每次给出两个碱基序列(包含ATGC的两个字符串),其中每一个碱基与另一串中碱基如果配对或者与空串对应会有一个分数(可能为负),找出一种方式使得两个序列配对的分数最大 思路:字符串动态规划的经 ...
- luogu3723 [AH2017/HNOI2017]礼物 【NTT】
题目 我的室友最近喜欢上了一个可爱的小女生.马上就要到她的生日了,他决定买一对情侣手 环,一个留给自己,一 个送给她.每个手环上各有 n 个装饰物,并且每个装饰物都有一定的亮度.但是在她生日的前一天, ...
- 5.24 Declaring Attributes of Functions【转】
转自:https://gcc.gnu.org/onlinedocs/gcc-4.0.0/gcc/Function-Attributes.html 5.24 Declaring Attributes o ...
- Luogu4491 [HAOI2018]染色 【容斥原理】【NTT】
题目分析: 一开始以为是直接用指数型生成函数,后来发现复杂度不对,想了一下容斥的方法. 对于有$i$种颜色恰好出现$s$次的情况,利用容斥原理得到方案数为 $$\binom{m}{i}\frac{P_ ...
- CF528D Fuzzy Search 【NTT】
题目链接 CF528D 题解 可以预处理出\(S\)每个位置能匹配哪些字符 对每种字符 构造两个序列 如果\(S[i]\)可以匹配该字符,则该位置为\(0\),否则为\(1\) 如果\(T[i]\)可 ...
- HDU 6061 RXD and functions(NTT)
题意 给定一个\(n\) 次的 \(f\) 函数,向右移动 \(m\) 次得到 \(g\) 函数,第 \(i\) 次移动长度是 \(a_i\) ,求 \(g\) 函数解析式的各项系数,对 ...
- 【NTT】hdu1402 A * B Problem Plus
r·2^k+1 r k g 3 1 1 2 5 1 2 2 17 1 4 3 97 3 5 5 193 3 6 5 257 1 8 3 7681 15 9 17 12289 3 12 11 40961 ...
随机推荐
- 《计算机组成原理 》& 《计算机网络》& 《数据库》 Roadmap for self-taugh student
计算机组成原理: UCB的这门课绝对是不错的资源. Great Ideas in Computer Architecture (Machine Structures) B站:https://www.b ...
- Python基础语法6-冒泡排序
用for循环实现冒泡排序(升序): array = [3,2,1] for i in range(len(array) - 1, 0, -1): for j in range(0, i): if ...
- 【Java】变量
变量 文章目录 变量 1.变量的概念 2.变量的三要素 3.变量的使用应该注意什么? 4.变量的声明和赋值.使用的语法格式? 5.code 1.变量的概念 变量的作用:变量用来存储数据. 变量的本质: ...
- 【计算机基础】常用的快捷键和DOS命令
常用的快捷键和DOS命令 DOS命令 使用Linux比较酷 cool
- C#中foreach的实现原理
C#中foreach的实现原理 在探讨foreach如何内部如何实现这个问题之前,我们需要理解两个C#里边的接口,IEnumerable 与 IEnumerator. 在C#里边的遍历集合时用到的相关 ...
- 汇编学习笔记——DOS及DEBUG介绍
转自:https://www.shiyanlou.com/courses/running/332 一.课程简介 声明:该课程基于<汇编语言(第2版)>郑晓薇 编著,机械工业出版社.本节实验 ...
- pandas数据分析API常用操作
1.导入数据 df = pd.read_csv( # 该参数为数据在电脑中的路径,可以不填写 filepath_or_buffer='/Users/Weidu/Desktop/sz000002.csv ...
- markdown编写文件目录结构
1.先全局安装tree cnpm i tree-node-cli -g 然后输入: tree --help -L 是确定要几级目录,-I是排除哪个文件夹下的,然后我是要在README里面生成项目结构树 ...
- [usaco2008 Oct]Pasture Walking 牧场旅行
题目描述 n个被自然地编号为1..n奶牛(1<=n<=1000)正在同样被方便的编号为1..n的n个牧场中吃草.更加自然而方便的是,第i个奶牛就在第i个牧场中吃草. 其中的一些对牧场被总共 ...
- 3A的限流芯片PW1503
PW1503是超低RDS(ON)开关,具有可编程的电流限制,以保护电源于过电流和短路情况.它具有超温保护以及反向闭锁功能. PW1503采用薄型(1毫米)5针薄型SOT封装,提供可调版本. 特征 ...