提交记录 2462


用户 题目 状态 得分 用时 内存 语言 代码长度
oscar 1002. 测测你的多项式乘法 Accepted 100 304.129 ms 52480 KB C++ 1.47 KB
提交时间 评测时间
2018-06-27 08:56:43 2020-07-31 21:02:59
#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);
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1304.129 ms51 MB + 256 KBAcceptedScore: 100


Judge Duck Online | 评测鸭在线
Server Time: 2024-04-29 23:46:01 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用