\(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】的更多相关文章

  1. 【推导】【NTT】hdu6061 RXD and functions(NTT)

    题意:给定一个n次多项式f(x)的各项系数,让你求f(x-Σai)的各项系数. http://blog.csdn.net/v5zsq/article/details/76780053 推导才是最关键的 ...

  2. 【NTT】loj#6261. 一个人的高三楼

    去年看过t老师写这题博客:以为是道神仙题 题目大意 求一个数列的$k$次前缀和.$n\le 10^5$. 题目分析 [计数]cf223C. Partial Sums 加强版.注意到最后的式子是$f_i ...

  3. POJ 1080 Human Gene Functions 【dp】

    题目大意:每次给出两个碱基序列(包含ATGC的两个字符串),其中每一个碱基与另一串中碱基如果配对或者与空串对应会有一个分数(可能为负),找出一种方式使得两个序列配对的分数最大 思路:字符串动态规划的经 ...

  4. luogu3723 [AH2017/HNOI2017]礼物 【NTT】

    题目 我的室友最近喜欢上了一个可爱的小女生.马上就要到她的生日了,他决定买一对情侣手 环,一个留给自己,一 个送给她.每个手环上各有 n 个装饰物,并且每个装饰物都有一定的亮度.但是在她生日的前一天, ...

  5. 5.24 Declaring Attributes of Functions【转】

    转自:https://gcc.gnu.org/onlinedocs/gcc-4.0.0/gcc/Function-Attributes.html 5.24 Declaring Attributes o ...

  6. Luogu4491 [HAOI2018]染色 【容斥原理】【NTT】

    题目分析: 一开始以为是直接用指数型生成函数,后来发现复杂度不对,想了一下容斥的方法. 对于有$i$种颜色恰好出现$s$次的情况,利用容斥原理得到方案数为 $$\binom{m}{i}\frac{P_ ...

  7. CF528D Fuzzy Search 【NTT】

    题目链接 CF528D 题解 可以预处理出\(S\)每个位置能匹配哪些字符 对每种字符 构造两个序列 如果\(S[i]\)可以匹配该字符,则该位置为\(0\),否则为\(1\) 如果\(T[i]\)可 ...

  8. HDU 6061 RXD and functions(NTT)

    题意 给定一个\(n​\) 次的 \(f​\) 函数,向右移动 \(m​\) 次得到 \(g​\) 函数,第 \(i​\) 次移动长度是 \(a_i​\) ,求 \(g​\) 函数解析式的各项系数,对 ...

  9. 【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 ...

随机推荐

  1. spring boot 邮件服务

    引入依赖 添加spring-boot-starter-mail包引用 <dependency> <groupId>org.springframework.boot</gr ...

  2. python的默认参数的一个坑

    前言 pass 正文 在 https://docs.python.org/3/tutorial/controlflow.html#default-argument-values 中,有这样一段话 Im ...

  3. 【C++】《Effective C++》第一章

    第一章 让自己习惯C++ C++是一个威力强大的语言,带着众多特性,但是在你可以驾驭其威力并有效运用其特性之前,你必须先习惯C++的办事方式. 条款01:视C++为一个语言联邦 如今的C++已经是个多 ...

  4. 《计算机组成原理 》& 《计算机网络》& 《数据库》 Roadmap for self-taugh student

    计算机组成原理: UCB的这门课绝对是不错的资源. Great Ideas in Computer Architecture (Machine Structures) B站:https://www.b ...

  5. idea中文注释出现乱码,我靠自己解决了

    如果你像我一样️,查遍google百度,半天下来还是找不到解决方案,说不定这篇博客能帮助你顺利解决呢 好了,那么开始说说我是怎么解决麻烦的. 首先,我想打开一份java文稿.光预览,它是没有任何问题的 ...

  6. spring mvc + mybaties + mysql 完美整合cxf 实现webservice接口 (服务端、客户端)

    spring-3.1.2.cxf-3.1.3.mybaties.mysql 整合实现webservice需要的完整jar文件 地址:http://download.csdn.net/detail/xu ...

  7. 1.5V升3.3V芯片电路图,稳压3.3V供电MCU模块等

    干电池1.5V可以升到3.3V,通过PW5100干电池升压IC,于外围3个元件:2个电容和一个电感即可组成1.5V升3.3V的电路系统. 干电池属于低能量的电池产品,不过一般使用到干电池的产品也是输出 ...

  8. SpringBoot 2.0 中 HikariCP 数据库连接池原理解析

    作为后台服务开发,在日常工作中我们天天都在跟数据库打交道,一直在进行各种CRUD操作,都会使用到数据库连接池.按照发展历程,业界知名的数据库连接池有以下几种:c3p0.DBCP.Tomcat JDBC ...

  9. bootstrap 轮播图带缩列图两端对齐,并自动换行然后左对齐!

    禁止自动轮播 data-interval="false" 完整代码如下: 1 <!DOCTYPE html> 2 <html> 3 4 <head&g ...

  10. VirtualBox Guest Additions 下载地址以及简介

    下载者可将以下链接粘贴到浏览器上,根据Vbox的版本找到自己对应的增强. http://download.virtualbox.org/virtualbox/5.0.10/ 虚拟机安装VBoxAddi ...