BZOJ-2194 快速傅立叶之二

FFT模版题。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cctype>
#include <complex>
#define rep(i, l, r) for(int i=l; i<=r; i++)
#define down(i, l, r) for(int i=l; i>=r; i--)
#define maxn 400009
#define cd complex <double>
#define PI acos(0.0)*2.0
#define ll long long
using namespace std;
{
int x=0, f=1; char ch=getchar();
while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while (isdigit(ch)) x=x*10+ch-'0', ch=getchar();
return x*f;
}
cd a[maxn], b[maxn], c[maxn], A[maxn];
int n, m, n1[maxn], n2[maxn], s[maxn];
int ans[maxn];

void fft(cd *a, bool flag)
{
rep(i, 0, n-1) s[i]=0;
for(int i=1, j=n; i<n; i*=2, j/=2) rep(h, j/2, j-1) s[h]+=i;
for(int i=1; i<n; i*=2) rep(j, 0, i-1) s[j+i]+=s[j];
rep(i, 0, n-1) A[i]=a[s[i]];
double pi=flag?PI:-PI;
for(int step=1; step<n; step*=2)
{
cd e=exp(cd(0, 2.0*pi/double(step*2))), w=cd(1, 0);
for (int pos=0; pos<step; pos++, w*=e)
for(int i=pos; i<n; i+=step*2)
{
cd ret=A[i], rec=w*A[i+step];
A[i]=ret+rec, A[i+step]=ret-rec;
}
}
if (!flag) rep(i, 0, n-1) A[i]/=n;
rep(i, 0, n-1) a[i]=A[i];
}

int main()
{
}