2017 多校3 hdu 6061 RXD and functions(FFT)

题意:

给一个函数\(f(x)=\sum_{i=0}^{n}c_i \cdot x^{i}\)
求\(g(x) = f(x - \sum a_i)\)后每一项\(x^{i}\)的系数mod998244353
\(n <= 10^{5},m <= 10^{5}\)
\(0 <= c_i < 998244353\)
\(0 <= a_i < 998244353\)

思路:

令\(d = -\sum a_i\),把\(g(x)\)展开得:
\[g(x) = c_0 (x + d)^{0} + c_1 (x + d)^{1} + ... + c_n (x+d)^{n}\]
令\(a_i = d^{i}\),再用二项式定理化简一下可以得到
\[g(x) = \sum_{i = 0}^{n}x^{i}\sum_{k=i}^{n}C(k,i)c_ka_{k-i}\]
\(fft\)只是入了门,想了半天,看不出来这是个卷积式子,组合数会变化啊,赛后终于开窍组合数是个阶乘啊,把\(c_k 和 a^{k-i}变换一下\)
令\[b_k = c_k \cdot k!, a_i = \frac{a_i}{i!}\]
\(g(x)\)就可以写成
\[g(x) = \sum_{i = 0}^{n}x^{i} \cdot \frac{1}{i!}\sum_{k=i}^{n}b_ka_{k-i}\]
令\(ans(i) = \frac{1}{i!} \sum_{k=i}^{n}b_ka_{k-i}\)
把b数组逆序一下
\(ans(i) = \frac{1}{i!}\sum_{k=0}^{n-i}b_{k}a_{n-k-i}\)

类比fft多项式乘法下面\(c_j\)的形式 \(\sum_{k=0}^{n-i}b_{k}a_{n-k-i}\)这一项其实就是\(fft\)之后得到的数组\(c_{n-i}\),最后答案\(ans(i) = \frac{1}{i!} c_{n-i}\)
\(A(x) = \sum_{i=0}^{n}a_ix^{i}\)
\(B(x) = \sum_{i=0}^{n}b_ix^{i}\)
\(C(x) = A(x)B(x) = \sum_{i=0}^{2n}c_ix^{i}\)
\(c_j = \sum_{i=0}^{j}a_ib_{j-i}\)

然后就上板子了,由于是在模意义下的运算,要拿ntt,去找了个板子
不太会用啊,板子上的费马素数是P=(1LL<<55) * 5+1,原根g=6的,
开始交了几发,TLE,原来是数组开小了,改完再交RE了,也不知道改了哪里就没RE了,然后WA了,暴力对拍数据,发现是费马素数的锅,乱试了其他的一些费马素数,又想了半天觉得这样不行,本来就是在mod下取的逆元,又在P下做运算,ntt原理也不懂,一脸懵逼,最后我直接把P改成mod试了一下,居然A了,好像给的这个mod本来是就是一个费马素数(1<<23) * 119 + 1,g = 3,而且运气好前面试的费马素数原根刚好是3。
还有疑问就是运算时费马素数应该取多大呢,==再深入学习一下

#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 2e5 + 1000;
const int mod = 998244353;
const LL P =  mod;
const LL G = 3;
const int NUM = 23;
int read(){int x = 0;char c;while((c=getchar())<'0'||c>'9');while(c>='0'&&c<='9')x=x*10+(c-'0'), c=getchar();return x;
}
int fac[N],facinv[N];
int n, m;
LL mul(LL x,LL y){//return (x * y - (LL)(x / (long double)P * y + 1e-3) * P + P) % P;return x * y % P;
}
LL q_pow(LL a,LL b){LL res = 1,tmp = a;while(b){if(b &1) res = res * tmp % P;tmp = tmp * tmp % P;b >>= 1;}return res;
}
void init(){fac[0] = facinv[0] = 1;for(int i = 1;i < N;i++){fac[i] = 1LL * i * fac[i-1] % mod;facinv[i] = 1LL * q_pow(i, mod - 2) * facinv[i - 1] % mod;}
}
LL  wn[NUM];
LL  a[2 * N], b[2 * N],c[N];
void GetWn()
{for(int i = 0; i< NUM; i++){int t = 1 << i;wn[i] = q_pow(G, (P - 1) / t);}
}
void Rader(LL a[], int len)
{int j = len >> 1;for(int i=1; i<len-1; i++){if(i < j) swap(a[i], a[j]);int k = len >> 1;while(j >= k){j -= k;k >>= 1;}if(j < k) j += k;}
}
void NTT(LL a[], int len, int on)
{Rader(a, len);int id = 0;for(int h = 2; h <= len; h <<= 1){id++;for(int j = 0; j < len; j += h){LL w = 1;for(int k = j; k < j + h / 2; k++){LL u = a[k];LL t = mul(w,a[k + h / 2]);a[k] = (u + t) % P;a[k + h / 2] = ((u - t) % P + P) % P;w = mul(w,wn[id]);}}}if(on == -1){for(int i = 1; i < len / 2; i++)swap(a[i], a[len - i]);LL Inv = q_pow(len, P - 2);for(int i = 0; i < len; i++)a[i] = mul(a[i],Inv);}
}
void Conv(LL a[], LL b[], int n)
{NTT(a, n, 1);NTT(b, n, 1);for(int i = 0; i < n; i++) a[i] = mul(a[i],b[i]);NTT(a, n, -1);
}
int main()
{GetWn();init();while(scanf("%d",&n) == 1){for(int i = 0;i <= n;i++) c[i] = read();int  sum = 0;m = read();for(int i = 1;i <= m;i++){int x;x = read();sum = (sum - x + mod) % mod;}int len = 1;while(len < 2 * (n + 1)) len <<= 1;int res = 1;for(int i = 0;i <= n;i++) {a[i] = 1LL * res * facinv[i] % mod, res = 1LL * res * sum % mod;b[i] = c[n - i] * fac[n - i] % mod;}for(int i = n + 1;i < len;i++) a[i] = b[i] = 0;Conv(a,b,len);for(int i = 0;i <= n;i++) printf("%lld ",a[n - i] * facinv[i] % mod);printf("\n");}return 0;
}

转载于:https://www.cnblogs.com/jiachinzhao/p/7273500.html

2017 多校3 hdu 6061 RXD and functions相关推荐

  1. HDU 6061 RXD and functions(NTT)

    RXD and functions 首先是有一个结论,对多项式做任意多次 transformation ,其结果跟做一次 transformation Tr(f,∑i=1mai)Tr(f, \sum\ ...

  2. 2017 多校2 hdu 6053 TrickGCD

    2017 多校2 hdu 6053 TrickGCD 题目: You are given an array \(A\) , and Zhu wants to know there are how ma ...

  3. hdu6103[尺取法] 2017多校6

    /*hdu6103[尺取法] 2017多校6*/ #include <bits/stdc++.h> using namespace std; int T, m; char str[2000 ...

  4. 2017 多校4 Wavel Sequence

    2017 多校4 Wavel Sequence 题意: Formally, he defines a sequence \(a_1,a_2,...,a_n\) as ''wavel'' if and ...

  5. RXD and functions HDU-6061 NTT

    RXD and functions solution gm=f(x−∑i=1mai),令A=∑i=1mai,则有,g_m=f(x-\sum\limits_{i=1}^{m}a_i),令A=\sum\l ...

  6. 2017 ACM暑期多校联合训练 - Team 3 1008 HDU 6063 RXD and math (莫比乌斯函数)...

    题目链接 Problem Description RXD is a good mathematician. One day he wants to calculate: ∑i=1nkμ2(i)×⌊nk ...

  7. 2017多校第3场 HDU 6058 Kanade's sum 双链表,思维

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6058 题外话:这场多校,真心感觉自己的无力,全队都发挥的很差,结束的时候排名掉到了90多,后期没做出字 ...

  8. HDU 6015 Colorful Tree(2017多校)

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6035 题意: 给出一颗树, 树上路径权值等于路径上不同颜色的数量,求所有路径权值之和: 解题思路: ...

  9. HDU 6044 Limited Permutation(2017多校)【计数 快速读入挂 线性逆元】

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6044 题意: 对于有n个元素的全排列的合法性定义为:有n个区间,对于第i个区间[li,ri]有li& ...

最新文章

  1. 使用Cacti监测系统与网络性能(3)
  2. DrawerLayout
  3. 分布式框架seata启动命令
  4. c语言随机生成整数存放一维数组_C语言入门教程(十)多维数组
  5. 四级单词pdf_2016年12月大学英语四级真题及答案解析(完整三套可打印)
  6. NYOJ 311 完全背包
  7. 用Python实现单向链表
  8. Little Elephant and Shifts(CF-220C)
  9. scheduledexecutorservice 的使用_java中ThreadPool的介绍和使用
  10. SurfaceView + MediaPlayer 实现列表循环播放视频
  11. Android 使用POI导出Excel表格
  12. 石光荣,黑客帝国,社会化网络----社会化网络能否平衡抽象主导的现代生活? (发表于程序员第一期)
  13. android 安装包反编译,Android逆向之反编译APK和安装包漏洞解析
  14. pythonpandas入门_pyhton pandas数据分析基础入门(一文看懂pandas)
  15. word批量修改图片的大小
  16. 别说 Python 会生成二维码,Java也会。
  17. Java实现OPC通信
  18. 原生js以及jQuery删除节点
  19. 微信封号被限制的几种原因及解决方法
  20. 大数据-大数据学习过程

热门文章

  1. 基于用户画像 《列变行》 特征打标显示
  2. ANT无线通信技术(2) 通道配置
  3. EMC开发实习生电面经验
  4. iOS 使用Quartz 2D画虚线 .
  5. SQL Server实用操作小技巧集合
  6. flash绘图API :flash player11新增的绘图API方法--cubicCurveTo
  7. Excel访问局域网中OLAP方案
  8. manjaro升级的一些问题
  9. 为什么要学习Python编程语言?哪些人适合学习Python?
  10. linux 分析磁盘性能,03.分析性能瓶颈 - 3.4.磁盘瓶颈 - 《Linux性能调优指南》 - 书栈网 · BookStack...