提交记录 7806


用户 题目 状态 得分 用时 内存 语言 代码长度
_WAautomaton 1002i. 【模板题】多项式乘法 Accepted 100 71.938 ms 158844 KB C++ 1.72 KB
提交时间 评测时间
2019-01-25 11:51:57 2020-08-01 01:08:41
// luogu-judger-enable-o2
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>

using std::swap;

const double Pi=M_PI;
const int maxn=1e7+100;

int limit=1,l=0;
int r[maxn];

struct complex
{
    double real,imag;
    complex(double r=0,double i=0):real(r),imag(i){};
    inline complex operator+ (const complex& c)
    {
        return complex(real+c.real,imag+c.imag);
    }
    inline complex operator- (const complex& c)
    {
    	return complex(real-c.real,imag-c.imag);
    }
    inline complex operator* (const complex& c)
    {
    	return complex(real*c.real-c.imag*imag,real*c.imag+c.real*imag);
    }
    void operator*= (const complex& c)
    {
    	double t=real*c.real-c.imag*imag;
    	imag=real*c.imag+c.real*imag;
    	real=t;
    }
};

inline void DFT(complex* A,int type)
{
    for (register int i=0;i<limit;++i)
    	if (i<r[i]) swap(A[i],A[r[i]]);
    for (register int mid=1;mid<limit;mid<<=1)
    {
    	complex wn(cos(Pi/mid),type*sin(Pi/mid));
    	for (register int R=mid<<1,j=0;j<limit;j+=R)
    	{
    		complex w(1,0);
    		for (register int k=0;k<mid;++k,w*=wn)
    		{
    			complex x=A[j+k],y=A[j+k+mid]*w;
    			A[j+k]=x+y;
    			A[j+k+mid]=x-y;
    		}
    	}
    }
}

//#define DEBUG 

int main()
{
    static complex a[maxn];
    int n,m;
    scanf("%d%d",&n,&m);
    while (limit<=(n+m)) limit<<=1,++l;
    for (register int i=0;i<=n;++i)
        scanf("%lf",&a[i].real);
    for (register int i=0;i<=m;++i)
        scanf("%lf",&a[i].imag);
    for (register int i=0;i<limit;++i)
    	r[i]=(r[i>>1]>>1)|((i&1)<<(l-1));
    DFT(a,1);
    for (register int i=0;i<=limit;++i)
        a[i]*=a[i];
    DFT(a,-1);
    for (register int i=0;i<=n+m;++i)
        printf("%d ",(int)(a[i].imag/(2*limit)+0.4));
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #117.111 ms152 MB + 640 KBAcceptedScore: 0

Subtask #1 Testcase #271.938 ms155 MB + 44 KBAcceptedScore: 0

Subtask #1 Testcase #342.321 ms153 MB + 408 KBAcceptedScore: 100

Subtask #1 Testcase #442.33 ms153 MB + 396 KBAcceptedScore: 0

Subtask #1 Testcase #517.779 ms152 MB + 640 KBAcceptedScore: 0

Subtask #1 Testcase #617.204 ms152 MB + 640 KBAcceptedScore: 0

Subtask #1 Testcase #717.062 ms152 MB + 640 KBAcceptedScore: 0

Subtask #1 Testcase #866.026 ms154 MB + 800 KBAcceptedScore: 0

Subtask #1 Testcase #966.108 ms154 MB + 800 KBAcceptedScore: 0

Subtask #1 Testcase #1059.051 ms154 MB + 532 KBAcceptedScore: 0

Subtask #1 Testcase #1171.713 ms155 MB + 124 KBAcceptedScore: 0

Subtask #1 Testcase #1271.903 ms154 MB + 4 KBAcceptedScore: 0

Subtask #1 Testcase #1317.327 ms152 MB + 640 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-04-07 20:38:29 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠