\(QwQ\)

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAXN 4000010
using namespace std; const double Pi = acos(-1.0); struct complex {
double x, y;
complex (double xx = 0, double yy = 0) {
x = xx, y = yy;
}
}a[MAXN], b[MAXN], c[MAXN]; complex operator + (complex a, complex b) {
return complex(a.x + b.x , a.y + b.y);
}
complex operator - (complex a, complex b) {
return complex(a.x - b.x , a.y - b.y);
}
complex operator * (complex a, complex b) {
return complex(a.x * b.x - a.y * b.y , a.x * b.y + a.y * b.x);
} int N, M, l, limit = 1, r[MAXN]; void fast_fast_tle (complex *A, int type) {
for (int i = 0; i < limit; i++) {
if (i < r[i]) {
swap(A[i], A[r[i]]);
}
//effect as A[i] = A_original[r[i]];
}
for (int mid = 1; mid < limit; mid <<= 1) {
complex Wn (cos(Pi / mid) ,type * sin(Pi / mid)); //w (1, mid);
for (int R = mid << 1, j = 0; j < limit; j += R) {
//R -> len of sequence
//j -> last position
complex w(1, 0); //w (0, mid);
for (int k = 0; k < mid; k++, w = w * Wn) {
complex x = A[j + k], y = w * A[j + mid + k];
A[j + k] = x + y;
A[j + mid + k] = x - y;
}
//mid对应当前的中间值,对应下一次的n。
}
}
} int main () {
cin >> N >> M;
for (int i = 0; i <= N; i++) cin >> a[i].x;
for (int i = 0; i <= M; i++) cin >> b[i].x;
while (limit <= N + M) limit <<= 1, l++;
for (int i = l - 1, p = 0; i >= 0; --i) {
int go_dis = 0;
while (go_dis < (1 << (l - i - 1))) {
p = p + 1;
r[p] = r[p - (1 << (l - i - 1))] + (1 << i);
++go_dis;
}
}
fast_fast_tle (a, 1);
fast_fast_tle (b, 1);
for (int i = 0; i < limit; i++) {
c[i] = a[i] * b[i];
}
fast_fast_tle(c, -1);
for (int i = 0; i <= N + M; i++) {
printf("%d ", (int)(c[i].x / limit + 0.5));
}
return 0;
}

附上\(nlogn\)高精乘法的板子

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 4000010
using namespace std; struct complex {
double x, y;
complex (double xx = 0, double yy = 0) {
x = xx, y = yy;
}
}a[N], b[N], c[N]; complex operator + (complex lhs, complex rhs) {
return complex (lhs.x + rhs.x, lhs.y + rhs.y);
} complex operator - (complex lhs, complex rhs) {
return complex (lhs.x - rhs.x, lhs.y - rhs.y);
} complex operator * (complex lhs, complex rhs) {
complex t;
t.x = lhs.x * rhs.x - lhs.y * rhs.y;
t.y = lhs.x * rhs.y + rhs.x * lhs.y;
return t;
} int read () {
int s = 0, w = 1, ch = getchar ();
while ('9' < ch || ch < '0') {
if (ch == '-') w = -1;
ch = getchar ();
}
while ('0' <= ch && ch <= '9') {
s = s * 10 + ch - '0';
ch = getchar ();
}
return s * w;
} int r[N];
int n, m, l, lim = 1;
const double pi = acos (-1); void fast_fast_tle (complex *A, int type) {
register int i, k, p, len, mid;
register complex Wn, w, x, y;
for (i = 0; i < lim; ++i) if (i < r[i]) swap (A[i], A[r[i]]);
for (mid = 1; mid < lim; mid *= 2) {
Wn = complex (cos (pi / mid), type * sin (pi / mid)); // w (1, mid);
for (len = mid * 2, p = 0; p < lim; p += len) {
w = complex (1, 0);
for (k = 0; k < mid; ++k, w = w * Wn) {// w (k, mid);
x = A[p + k], y = w * A[p + k + mid];
A[p + k] = x + y;
A[p + k + mid] = x - y;
}
}
}
} int main () {
n = read (), m = read ();
register int i, p, go_dis;
for (i = 0; i <= n; ++i) a[i].x = read ();
for (i = 0; i <= m; ++i) b[i].x = read ();
while (lim <= n + m) lim <<= 1, ++l;
for (i = l - 1, p = 0; i >= 0; --i) {
go_dis = 0;
while (go_dis < (1 << (l - i - 1))) {
p = p + 1;
r[p] = r[p - (1 << (l - i - 1))] + (1 << i);
++go_dis;
}
}
fast_fast_tle (a, +1);
fast_fast_tle (b, +1);
for (i = 0; i < lim; ++i) c[i] = a[i] * b[i];
fast_fast_tle (c, -1);
for (i = 0; i <= n + m; ++i) printf ("%d ", (int) (c[i].x / lim + 0.5)); }

maomao的fft板子的更多相关文章

  1. FFT板子

    woc......FFT这玩意儿真坑...... 一上午除了打了几遍板子什么也没干......真是废了...... 你要加油啊...... #include<cstdio> #includ ...

  2. 高精乘(fft板子

    哇..fft的原理真的是不太好懂,看了好久许多细节还是不太清楚,但感觉本质就是用了单位根的性质. https://www.luogu.org/problem/P1919 #include<cst ...

  3. FFT && NTT板子

    贴板子啦-- FFT板子:luogu P3803 [模板]多项式乘法(FFT) #include<cstdio> #include<iostream> #include< ...

  4. 卷积FFT、NTT、FWT

    先简短几句话说说FFT.... 多项式可用系数和点值表示,n个点可确定一个次数小于n的多项式. 多项式乘积为 f(x)*g(x),显然若已知f(x), g(x)的点值,O(n)可求得多项式乘积的点值. ...

  5. maomao的每日动向

    \(2019.02.04\) \(Nothing\) \(to\) \(do\). \(2019.02.05\) - 早上睡到\(12\)点 - 中午下午:吃饭串门拜年 - 晚上:吹爆<流浪地球 ...

  6. bzoj 4332 FFT型的快速幂(需要强有力的推导公式能力)

     有n个小朋友,m颗糖,你要把所有糖果分给这些小朋友. 规则第 i 个小朋友没有糖果,那么他之后的小朋友都没有糖果..如果一个小朋友分到了 xx 个糖果,那么的他的权值是 f(x) = ox^2 +  ...

  7. 【FFT】hdu1402 A * B Problem Plus

    FFT板子. 将大整数看作多项式,它们的乘积即多项式的乘积在x=10处的取值. #include<cstdio> #include<cmath> #include<cst ...

  8. noip前打板子 qwq

    在某咕上打了一晚上的模板 感觉还好... #include<bits/stdc++.h> #define LL long long using namespace std; inline ...

  9. UVa12298(生成函数的简单应用+FFT)

    I have a set of super poker cards, consisting of an infinite number of cards. For each positive compo ...

随机推荐

  1. SpringBoot之加载自定义配置文件

    SpringBoot默认加载配置文件名为:application.properties和application.yml,如果需要使用自定义的配置文件,则通过@PropertySource注解指定. J ...

  2. XCTF 4th-WHCTF-2017 creakme

    exe文件 运行一下 随便输一下 ps.这个曹操身边的故事挺有意思的 但是没啥卵用....... 查一下壳无壳 ida载入 发现找不到main函数 直接看start感觉逻辑乱乱的(萌新求不喷..... ...

  3. powerdesigner 16.5 不允许有扩展属性,或对象不存在

    创建完之后这边会出现 选择刚创建的用户 这样就可以了

  4. const函数

    1. const修饰成员函数:表示不可以修改成员变量 class test{ public: test(){ i_ = ; } int Get() const{ //i_ = 0; //error:不 ...

  5. hdu-1814(2-sat)

    题意:给你n个组,m条规则,每组有俩个人,这两个人不能同时出现,然后m条规则代表着有两个人,这两个人也不能同时出现,问你是否存在每组都能出现一人的选择方案 解题思路:因为这个需要字典序输出,所以只能用 ...

  6. POJ 2823 滑动窗口 单调队列

    https://vjudge.net/problem/POJ-2823 中文:https://loj.ac/problem/10175 题目 给一个长度为 $N$ 的数组,一个长为 $K$ 的滑动窗体 ...

  7. JVM是如何处理异常的

    JVM处理异常 异常处理的两大组成要素是抛出异常和捕获异常.这两大要素共同实现程序控制流的非正常转移. 抛出异常可分为显式和隐式两种.显式抛异常的主体是应用程序,指的是在程序中使用throw关键字,手 ...

  8. linux系统版本大全

    Linux系统下载地址:http://www.jb51.net/LINUXjishu/239493.html linux系统教学视频:http://www.uplinux.com/shipin/lin ...

  9. 【XSY2771】城市 分治

    题目描述 一个平原上有\(n\)个城市,第\(i\)个城市在点\((\cos \frac{2i\pi}{n},\sin \frac{2i\pi}{n})\)上. 每个城市和最近的两个城市有一条直线段的 ...

  10. LOJ2255. 「SNOI2017」炸弹 (线段树)

    本文为线段树做法 (听说可以tarjan缩点+拓扑? 感觉差不多..而且这样看起来方便很多 找到左端点的过程可以看作 点 -> 区间内lowerbound最小的点 -> lowerboun ...