HDU 6061 RXD and functions(NTT+卷积)
2017-08-04 12:07
453 查看
传送门
Total Submission(s): 532 Accepted Submission(s): 211
[align=left]Problem Description[/align] RXD has a polynomial function f(x), f(x)=∑ni=0cixi
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
[align=left]Input[/align] There are several test cases, please keep reading until EOF.
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
[align=left]Output[/align] For each test case, output an polynomial with degree n, which means the answer.
[align=left]Sample Input[/align]
[align=left]Sample Output[/align]
Hint
(x−1)2=x2−2x+1
题目大意:
已知多项式 f(x)=∑ni=0cixi 求 f(x−∑ai)
解题思路:
令 −t=∑ai
f(x)=∑ni=0ci(x+t)i
将 (x+t)i用二项式定理展开后得到:
f(x)将组合数展开:将i!提到前面:=∑i=0nci∑j=0ixjCjiti−j=∑i=0nxi∑j=incj∗Cijtj−i=∑i=0nxi∑j=incj∗j!i!∗(j−i)!tj−i=∑i=0nxii!∑j=incj∗j!tj−i(j−i)!
我们将其系数提出来:f′(x)=∑j=incj∗j!tj−i(j−i)!
令 bi=cn−i∗(n−i)!,则有:
f′(x)=∑j=inbn−jtj−i(j−i)!
通过观察发现: (n−j)+(j−i)=n−i
现在设:h=n−i,则有:
f′(x)=∑j=0hbh−jtjj!
这是个卷积形式,因为是模意义下的,我们可以根据 NTT 求出f′(x)的系数,但是在真正的 f(x) 里,f(i)=f′(n−i)i!。
我们需要预处理阶乘逆元,以及阶乘,然后通过 NTT 计算 f′(x),最后计算 f(x) 系数就OK了。
代码:
RXD and functions
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 532 Accepted Submission(s): 211
[align=left]Problem Description[/align] RXD has a polynomial function f(x), f(x)=∑ni=0cixi
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
[align=left]Input[/align] There are several test cases, please keep reading until EOF.
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
[align=left]Output[/align] For each test case, output an polynomial with degree n, which means the answer.
[align=left]Sample Input[/align]
2 0 0 1 1 1
[align=left]Sample Output[/align]
1 998244351 1
Hint
(x−1)2=x2−2x+1
题目大意:
已知多项式 f(x)=∑ni=0cixi 求 f(x−∑ai)
解题思路:
令 −t=∑ai
f(x)=∑ni=0ci(x+t)i
将 (x+t)i用二项式定理展开后得到:
f(x)将组合数展开:将i!提到前面:=∑i=0nci∑j=0ixjCjiti−j=∑i=0nxi∑j=incj∗Cijtj−i=∑i=0nxi∑j=incj∗j!i!∗(j−i)!tj−i=∑i=0nxii!∑j=incj∗j!tj−i(j−i)!
我们将其系数提出来:f′(x)=∑j=incj∗j!tj−i(j−i)!
令 bi=cn−i∗(n−i)!,则有:
f′(x)=∑j=inbn−jtj−i(j−i)!
通过观察发现: (n−j)+(j−i)=n−i
现在设:h=n−i,则有:
f′(x)=∑j=0hbh−jtjj!
这是个卷积形式,因为是模意义下的,我们可以根据 NTT 求出f′(x)的系数,但是在真正的 f(x) 里,f(i)=f′(n−i)i!。
我们需要预处理阶乘逆元,以及阶乘,然后通过 NTT 计算 f′(x),最后计算 f(x) 系数就OK了。
代码:
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int MAXN = 3e5+5; const LL MOD = 998244353; const double eps = 1e-8; const double PI = acos(-1.0); LL c[100005], fac[100005], Inv[100005], ans[MAXN]; void Init(){ fac[0] = Inv[0] = fac[1] = Inv[1] = 1; for(int i=2; i<100005; i++) fac[i] = fac[i-1] * i % MOD; for(int i=2; i<100005; i++) Inv[i] = (MOD - MOD / i) * Inv[MOD % i] % MOD; for(int i=2; i<100005; i++) Inv[i] = Inv[i] * Inv[i-1] % MOD; } ///const LL P = (479 << 21) + 1;//费马素数 const LL P = MOD; const LL G = 3;//原根 const LL NUM = 20; LL wn[NUM]; LL Pow(LL a, LL b, LL m){ LL ans = 1; a %= m; while(b){ if(b & 1) ans = ans*a%m; b>>=1; a = a*a%m; } return ans; } void GetWn() { for(int i = 0; i < NUM; i++) { LL t = 1LL << i; wn[i] = Pow(G, (P - 1) / t, P); } } void change(LL * y, LL len) { LL i, j, k; for (i = 1, j = len / 2; i < len - 1; i++) { if (i < j) swap(y[i], y[j]); k = len / 2; while (j >= k) { j -= k; k /= 2; } if (j < k) j += k; } } void ntt(LL *y, LL len, LL on) { change(y, len); LL id = 0; for (LL h = 2; h <= len; h <<= 1) { id++; for (LL j = 0; j < len; j += h) { LL w = 1; for (LL k = j; k < j + h / 2; k++) { LL u = y[k] % P; LL t = w * y[k + h / 2] % P; y[k] = (u + t) % P; y[k + h / 2] = (u - t + P) % P; w = w * wn[id] % P; } } } if(on == -1) { for(LL i = 1; i < len / 2; i++) swap(y[i], y[len - i]); LL inv = Pow(len, P - 2, P); for(LL i = 0; i < len; i++) y[i] = y[i] * inv % P; } } LL a[MAXN], b[MAXN]; int main() { ///freopen("in.txt", "r", stdin); Init(); GetWn(); int n; while(~scanf("%d", &n)){ memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); n++; for(int i=0; i<n; i++) scanf("%lld", &c[i]); int m; scanf("%d", &m); LL x, sum = 0; while(m--) scanf("%lld", &x), sum = (sum + x) % MOD; sum = (-sum + MOD) % MOD; if(sum == 0){ for(int i=0; i<n; i++) printf("%lld ", c[i]); puts(""); continue; } LL len = 1; while(len < (2*n)) len<<=1LL; LL s = 1; for(int i=0; i<n; i++){ a[i] = c[n-1-i] * fac[n-1-i] % MOD; b[i] = s * Inv[i] % MOD; s = s * sum % MOD; } ntt(a, len, 1), ntt(b, len, 1); for(int i=0; i<len; i++) a[i] = a[i] * b[i] % MOD; ntt(a, len, -1); for(int i=0; i<n; i++) printf("%lld ",a[n-1-i]*Inv[i]%MOD); puts(""); } return 0; }
相关文章推荐
- [HDU] 6061 RXD and functions [NTT]
- HDU 6061 RXD and functions NTT
- HDU 6061 RXD and functions(NTT)
- 解题报告:HDU_6061 RXD and functions NTT
- HDU 6061 RXD and functions
- HDU 6061 RXD and functions
- 2017 多校3 hdu 6061 RXD and functions
- 2017 多小训练第三场 HDU 6061 RXD and functions
- hdu 6061 RXD and functions [快速数论变换]
- 【推导】【NTT】hdu6061 RXD and functions(NTT)
- HDU-6060 RXD and dividing - 2017 Multi-University Training Contest - Team 3(思维+最小斯坦纳树)
- HDU 6064 RXD and numbers(BEST theorem)
- HDU 6064 RXD and numbers(BEST定理)
- 【思维】hdu 6060 RXD and dividing
- RXD and math HDU - 6063
- [HDU]-6060 RXD and dividing
- HDU 6063 RXD and math【数学】
- HDU 6065 RXD, tree and sequence (LCA, 2017 Multi-Univ Training Contest 3)
- HDU 6063 RXD and math(快速幂)
- HDU 6060 RXD and dividing