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 推导才是最关键的 ...
随机推荐
- system sys,sysoper sysdba 的区别
--===================================== -- system sys,sysoper sysdba 的区别 --========================= ...
- nginx的详解(二)
查看几个设置 nginx正则表达式常用的是前6个 ^: 匹配字符串的开始位置: $:匹配字符串的结束位置:.*: .匹配任意字符,*匹配数量0到正无穷: \. 斜杠用来转义,\.匹配 . 特殊使用方法 ...
- 1.ruby基本格式
1.ruby对于空格是敏感的,很像shell 如:a + b 解释成 a+b(这是两个局部变量) a +b 解释成 a(+b) (这是一个方法调用) 2.在ruby中一行怎么才算结束? Ruby解释分 ...
- 高一python笔记大全(过会考)
最初のプログラム xfは.どちらかの試合(しあい)活動(かつどう)に参加して.a秒(aは整数)を使ったのですが.今あなたがひとつ任務を有:分と秒数を出力するください. a=int(input(&quo ...
- Chrome中输入框默认样式移除
Chrome中输入框默认样式移除 在chrome浏览器中会默认给页面上的输入框如input.textarea等渲染浏览器自带的边框效果 IE8中效果如下: Chrome中效果如下: 这在我们未给输 ...
- hdu 5040 Instrusive【BFS+优先队列】
11733274 2014-09-26 12:42:31 Accepted 5040 62MS 1592K 4848 B G++ czy 先转一个优先队列的用法: http://www.cppblog ...
- Java学习:一 开篇
呃 工作中要用到Android开发,呃 不巧的是,关于Java关于Android,当初也只是浅浅的了解了一下.....真是书到用时方恨少了.. 趁现在工作不是太忙,还是花点时间来学习一下吧. 写写博客 ...
- UTF-8 编码的文件在处理时要注意 BOM 文件头问题
最近在给项目团队开发一个基于 Java 的通用的 XML 分析器时,设计了一个方法,能够读取现成的 XML 文件进行分析处理,当然 XML 都是采用 UTF-8 进行编码的.但是在用 UltraEdi ...
- AC日记——草地排水 codevs 1993
1993 草地排水 USACO 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 在农夫约翰的农场上,每 ...
- 2716 [Violet 3] 天使玩偶
@(BZOJ)[CDQ分治] Sample Input 100 100 81 23 27 16 52 58 44 24 25 95 34 2 96 25 8 14 97 50 97 18 64 3 4 ...