思路:
为什么好多字符串的题都可以用FFT啊....
我们其实是要判断$\Sigma (a[i]-b[i])^2*a[i]*b[i]==0$
那就把a串翻转过来 把 上式展开
大力做几遍FFT就好啦~
//By SiriusRen#include#include #include #include using namespace std;#define double long doubleconst double pi=acos(-1);const int N=666666;int nn,mm,n,L,R[N],all;struct Complex{ double x,y;Complex(){} Complex(double X,double Y){x=X,y=Y;}}A[N],B[N],ans[N];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);}Complex operator/(Complex a,int b){ return Complex(a.x/b,a.y/b);}void FFT(Complex *E,int f){ for(int i=0;i >1]>>1)|((i&1)<<(L-1)); reverse(a,a+mm); for(int i=0;i