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 ...
随机推荐
- 使用Python自动填写问卷星(pyppeteer反爬虫版)
写此文的目的是为了方便寒假自己忘记填问卷星 一开始的想法和去年一样,去年就写过一版,想着今年不过就是改改数据,换换id而已,另外没想到的事情发生了... 满怀信心的写完代码 from selenium ...
- LeetCode167 两数之和 II - 输入有序数组
给定一个已按照升序排列 的有序数组,找到两个数使得它们相加之和等于目标数. 函数应该返回这两个下标值 index1 和 index2,其中 index1 必须小于 index2. 说明: 返回的下标值 ...
- IntelliJ IDEA启动界面的秘密:当编程遇到艺术
细心的同学会发现Intellij IDEA每次发版本的时候都会有不同的启动界面背景,都很比较抽象的艺术图像. JetBrains的其它产品也有自己独特的设计. 但是这背后是怎么实现的.有什么寓意却很少 ...
- LRU缓存的实现
文章目录 LRU简介 LRU算法分析 实现代码 节点类 双向链表 LRUCache类 测试类 总结 LRU简介 LRU是"Least Recently Used"的简写,意思是最近 ...
- Nginx 实现动态负载均衡(Nginx-1.10.1 + Consul v0.6.4)
一直也没有找到合适的类似Socat + Haproxy 的组合能用在Nginx,后来发现了Nginx的几个模块,但是也存在各种不足. 而且Nginx 在大流量的情况下nginx -s reload 是 ...
- 【Linux】nohup和&的区别
同样都是后台执行进程,但是nohup和&有什么区别呢? & 是指后台运行: nohup 的功能和& 之间的功能并不相同. 其中,nohup 可以使得命令永远运行下去和用户终端没 ...
- ctfhub技能树—信息泄露—hg泄露
打开靶机 查看页面信息 使用dvcs-ripper工具进行处理 ./rip-hg.pl -v -u http://challenge-cf630b528f6f25e2.sandbox.ctfhub.c ...
- mysql—group_concat函数
MySQL中的group_concat函数的使用方法,比如select group_concat(name) . 完整的语法如下: group_concat([DISTINCT] 要连接的字段 [Or ...
- Java-Servlet知识总结
目录 Servlet概述 为什么要学习Servlet 什么是 Servlet 工作流程 生命周期 处理请求的方法 HttpServletRequest 和 HttpServletResponse Ht ...
- 三. SpringCloud服务注册与发现
1. Eureka 1.1 Eureka理解 什么是服务治理 Spring Cloud封装了Netflix公司开发的Eurkeka模块来实现服务治理 在传统的rpc远程调用框架中,管理每个服务与服务之 ...