structComplex { double x,y; Complex() {} Complex(double x, double y):x(x),y(y) {} Complex operator+(const Complex& t) const {returnComplex(x+t.x,y+t.y);} Complex operator-(const Complex& t) const {returnComplex(x-t.x,y-t.y);} Complex& operator*=(const Complex& t) {staticdouble q;q=x*t.x-y*t.y;y=x*t.y+y*t.x;x=q;return *this;} Complex operator*(const Complex& t) const {Complex ret=*this;return ret*=t;} }; char a[nmax],b[nmax]; int m,n; int fi,pr[nmax]; int len; Complex AA[nmax],B[nmax]; int rev[nmax]; int ans[nmax]; inlinevoidfft(Complex* a, int inv){ static Complex w,delta,x,y; staticint i,j,k; for (i=0;i<len;i++) if (i<rev[i]) swap(a[i],a[rev[i]]); for (i=1;i<len;i<<=1) { delta.x=cos(delta.y=PI/i); delta.y=inv*sin(delta.y); for (j=0;j<len;j+=(i<<1)) { w.x=1,w.y=0; for (k=0;k<i;k++,w*=delta) { x=a[j+k],y=a[i+j+k]*w; a[j+k]=x+y,a[i+j+k]=x-y; } } } if (inv==-1) for (i=0;i<len;i++) a[i].x/=len; } intmain(){ cin>>(a+1)>>(b+1); m=strlen(a+1); n=strlen(b+1); registerint i,j; for (i=1;i<=m;i++) AA[m-i+1].x=a[i]-='a',fi+=a[i]*a[i]; for (i=1;i<=n;i++) B[i].x=b[i]-='a',pr[i]=pr[i-1]+b[i]*b[i]; i=j=m+n; do { len=i&(-i); i&=~len; } while (i); if (len!=j) len<<=1;
for (i=1;i<len;i++) { rev[i]=rev[i>>1]>>1; if (i&1) rev[i]^=(len>>1); } fft(AA,1),fft(B,1); for (i=0;i<len;i++) AA[i]*=B[i]; fft(AA,-1); j=n-m+1; for (int x=1;x<=j;x++) if (!(fi+pr[x+m-1]-pr[x-1]-int(2*AA[m+x].x))) ans[++ans[0]]=x; cout<<ans[0]<<endl; for (i=1;i<=ans[0];i++) cout<<ans[i]<<' '; cout<<endl; return0; }
#define nmax 1048600 constdouble PI = acos(-1); usingnamespace std;
structComplex { double x,y; Complex() {} Complex(double x, double y):x(x),y(y) {} inline Complex& operator+=(const Complex& t) {x+=t.x;y+=t.y;return *this;} Complex operator+(const Complex& t) const {Complex ret=*this;return ret+=t;} inline Complex& operator-=(const Complex& t) {x-=t.x;y-=t.y;return *this;} Complex operator-(const Complex& t) const {Complex ret=*this;return ret-=t;} inline Complex& operator*=(const Complex& t) {staticdouble q;q=x*t.x-y*t.y;y=x*t.y+y*t.x;x=q;return *this;} Complex operator*(const Complex& t) const {Complex ret=*this;return ret*=t;} }; char a[nmax],ao[nmax],b[nmax]; //ao是原来的,a是倒过来的 int m,n; int len; Complex A[nmax],B[nmax],C[nmax]; int rev[nmax]; int ans[nmax]; inlinevoidfft(Complex* a, int inv){ static Complex w,delta,x,y; staticint i,j,k; for (i=0;i<len;i++) if (i<rev[i]) swap(a[i],a[rev[i]]); for (i=1;i<len;i<<=1) { delta.x=cos(delta.y=PI/i); delta.y=inv*sin(delta.y); for (j=0;j<len;j+=(i<<1)) { w.x=1,w.y=0; for (k=0;k<i;k++,w*=delta) { x=a[j+k],y=a[i+j+k]*w; a[j+k]=x+y,a[i+j+k]=x-y; } } } if (inv==-1) for (i=0;i<len;i++) a[i].x/=len; } intmain(){ cin>>m>>n>>(ao+1)>>(b+1); registerint i,j; for (i=1,j=m;i<=m;i++,j--) if (ao[i]=='*') a[j]=0; else a[j]=ao[i]-'a'+1; //要保证'a'对应的是1而不是0,只有通配符能是0 for (i=1;i<=n;i++) if (b[i]=='*') b[i]=0; else b[i]-='a'-1; i=j=m+n; do { len=i&(-i); i&=~len; } while (i); if (len!=j) len<<=1;
for (i=1;i<len;i++) { rev[i]=rev[i>>1]>>1; if (i&1) rev[i]^=(len>>1); } //第一个部分 A[0].x=A[0].y=B[0].x=B[0].y=0; for (i=1;i<=len;i++) { A[i].x=(double)a[i]*a[i]*a[i],A[i].y=0; B[i].x=(double)b[i],B[i].y=0; } fft(A,1),fft(B,1); for (i=0;i<=len;i++) A[i]*=B[i],C[i]+=A[i]; //第二个部分 A[0].x=A[0].y=B[0].x=B[0].y=0; for (i=1;i<=len;i++) { A[i].x=(double)a[i]*a[i],A[i].y=0; B[i].x=(double)b[i]*b[i],B[i].y=0; } fft(A,1),fft(B,1); Complex two(2,0); for (i=0;i<=len;i++) A[i]*=B[i],A[i]*=two,C[i]-=A[i]; //第三个部分 A[0].x=A[0].y=B[0].x=B[0].y=0; for (i=1;i<=len;i++) { A[i].x=(double)a[i],A[i].y=0; B[i].x=(double)b[i]*b[i]*b[i],B[i].y=0; } fft(A,1),fft(B,1); for (i=0;i<=len;i++) A[i]*=B[i],C[i]+=A[i];
//最后再IFFT fft(C,-1);
j=n-m+1; for (int x=1;x<=j;x++) if (!int(C[m+x].x+0.5)) ans[++ans[0]]=x; cout<<ans[0]<<endl; for (i=1;i<=ans[0];i++) cout<<ans[i]<<' '; cout<<endl; return0; }