Code Tree
-
https://github.com/tiger2005/algorithm-templates/blob/main/lib/gf/poly.h
poly.h 实现了固定模数的多项式,并给出了各种操作的优秀实现。在这个模板中,除了基础操作的卡常外,还包括多点求值和快速插值的转置写法,可以查看同目录下的 multipoint.h 和 interpolate.h。
z.h 实现了固定剩余系内的元素,并实现了基础的四则运算。
montgomery.h 为给定的模数构建了 Montgomery 空间,用于加快 z.h 中相关计算。
log2.h 用神奇的位运算加快了对 2 的整数次幂的 log2 求解。
quadratic_mod.h 实现了 Z 类的二次剩余,这个没啥好说的。
感谢 hly1204 的悉心教导(?),以及以下博客的启发:
- https://oi-wiki.org/math/poly/intro/ OI Wiki 的全套介绍;
- https://loj.ac/d/3165 让我重新理解了 FFT;
- https://www.luogu.com.cn/blog/vocalise/multipoint-interpolation-vandermonde 教会我转置做法的思想;
- https://negiizhao.blog.uoj.ac/blog/4671 提供了非常优质的基础操作卡常小技巧;
- https://hly1204.blog.uoj.ac/blog/7319 exp 实现方案使用到的半在线卷积,具体可参考
poly.h的末尾。
下面是对这个模板库的简单测试,引用了 IO 库和 Poly 类实现必要的库。若无特殊说明,统一禁用 块读,并使用 C++20 和 O2 编译开关。
| 模板题 | 提交记录 | 时间(最大 / 全部) | 规模 |
|---|---|---|---|
| P3803 【模板】多项式乘法(FFT) | # | 293ms / 754ms | |
| P4238 【模板】多项式乘法逆 | # | 37ms / 262ms | |
| P4725 【模板】多项式对数函数(多项式 ln) | # | 53ms / 265ms | |
| P4726 【模板】多项式指数函数(多项式 exp) | # | 42ms / 204ms | |
| P5273 【模板】多项式幂函数(加强版) | # | 82ms / 669ms | |
| P5277 【模板】多项式开根(加强版) | # | 40ms / 356ms | |
| P4512 【模板】多项式除法 | # | 62ms / 328ms | |
| P5050 【模板】多项式多点求值 | # | 236ms / 2.30s | |
| P5158 【模板】多项式快速插值 | # | 746ms / 5.30s | |
| P5264 多项式三角函数 | # | 70ms / 423ms | |
| P5265 多项式反三角函数 | # | 94ms / 463ms | |
| #150. 挑战多项式 | # | 156ms / 2849ms | |
#150. 挑战多项式(-Ofast,启动块读) | # | 106ms / 2065ms |