模板题。
将
bbb序列反过来然后上
fftfftfft搞定。
代码:
#include #define ri register intusing namespace std;inline int read(){ int ans=0; char ch=getchar(); while(!isdigit(ch))ch=getchar(); while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar(); return ans;}const int N=4e5+5;const double pi=acos(-1.0);struct Complex{ double x,y; inline Complex operator+(const Complex&b){ return (Complex){ x+b.x,y+b.y};} inline Complex operator-(const Complex&b){ return (Complex){ x-b.x,y-b.y};} inline Complex operator*(const Complex&b){ return (Complex){ x*b.x-y*b.y,x*b.y+y*b.x};} inline Complex operator/(const double&b){ return (Complex){ x/b,y/b};}}a[N],b[N];int n,pos[N],lim,tim;inline void init(){ lim=1,tim=0; while(lim<=n*2)lim<<=1,++tim; for(ri i=0;i >1]>>1)|((i&1)<<(tim-1));}inline void fft(Complex *a,int type){ for(ri i=0;i