# bzoj2194

http://www.lydsy.com/JudgeOnline/problem.php?id=2194

#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
const int N = 600010;
complex<double> a[N], b[N];
int n, m, l;
int r[N];
void fft(complex<double> *a, int f)
{
for(int i = 0; i <= n; ++i) if(i < r[i]) swap(a[i], a[r[i]]);
for(int i = 1; i < n; i <<= 1)
{
complex<double> w(cos(pi / i), f * sin(pi / i));
for(int p = i << 1, j = 0; j <= n; j += p)
{
complex<double> t(1, 0);
for(int k = 0; k < i; ++k, t = t * w)
{
complex<double> x = a[j + k], y = t * a[j + k + i];
a[j + k] = x + y; a[j + k + i] = x - y;
}
}
}
}
int main()
{
scanf("%d", &n); --n;
for(int i = 0; i <= n; ++i)
{
int x, y; scanf("%d%d", &x, &y); a[i] = x; b[n - i] = y;
}
m = 2 * n; for(n = 1; n <= m; n <<= 1) ++l;
for(int i = 0; i <= n; ++i) r[i] = (r[i >> 1] >> 1) | ((i & 1) << (l - 1));
fft(a, 1); fft(b, 1);
for(int i = 0; i <= n; ++i) a[i] = a[i] * b[i];
fft(a, -1);
for(int i = m / 2; i <= m; ++i) printf("%d\n", (int)(a[i].real() / n + 0.5));
return 0;
}
View Code

posted @ 2017-05-17 22:52  19992147  阅读(61)  评论(0编辑  收藏  举报