#include<math.h>
using namespace std;
const double pi=3.1415926535897932384626433832795;
const int MAXV=1000000;
struct c
{
double r,i;
inline c(){r=i=0.0;}
inline c(const double a,const double b){r=a,i=b;}
inline c operator+(const c &x)const{return c(r+x.r,i+x.i);}
inline c operator+=(const c &x){return *this=*this+x;}
inline c operator-(const c &x)const{return c(r-x.r,i-x.i);}
inline c operator-=(const c &x){return *this=*this-x;}
inline c operator*(const c &x)const{return c(r*x.r-i*x.i,r*x.i+i*x.r);}
inline c operator*=(const c &x){return *this=*this*x;}
inline c conj(){return c(r,-i);}
}A[2333333];
int r[2333333],l=1;
inline void swap(c &x,c &y){c t=x;x=y;y=t;}
inline void fft(c *a,int ty)
{
for(int i=0;i<l;i++)i<r[i]?(void)(0):swap(a[i],a[r[i]]);
for(int i=1;i<l;i<<=1)
{
c w(cos(pi/i),ty*sin(pi/i));
for(int j=0;j<l;j+=i<<1)
{
c wn(1.0,0.0);
for(int k=j;k<i+j;k++)
{
c t=a[i+k]*wn;
a[i+k]=a[k]-t;
a[k]+=t;
wn*=w;
}
}
}
}
void poly_multiply(unsigned *a, int n, unsigned *b, int m, unsigned *z)
{
for(int i=0;i<=n;i++)A[i].r=a[i];
for(int i=0;i<=m;i++)A[i].i=b[i];
while(l<=n+m)l<<=1;
for(int i=1;i<l;i<<=1)
for(int j=0;j<i;j++)
r[i+j]=r[j]+l/(i<<1);
fft(A,1);
A[l]=A[0];
for(int i=0;i<=l-i;i++)
{
c t=(A[i]+A[l-i].conj())*c(0.0,-0.25)*(A[i]-A[l-i].conj());
c t2=(A[l-i]+A[i].conj())*c(0.0,-0.25)*(A[l-i]-A[i].conj());
A[i]=t;A[l-i]=t2;
}
fft(A,-1);
double invl=1.0/l;
for(int i=0;i<=n+m;i++)z[i]=int(A[i].r*invl+0.5);
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 304.129 ms | 51 MB + 256 KB | Accepted | Score: 100 | 显示更多 |