提交记录 4630


用户 题目 状态 得分 用时 内存 语言 代码长度
Hzyuer 1002i. 【模板题】多项式乘法 Accepted 100 29.377 ms 16424 KB C++ 1.77 KB
提交时间 评测时间
2018-07-26 19:29:35 2020-07-31 23:09:09
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const int Maxn=300005;
const double pi=acos(-1);
inline char C(){
    static char buf[1<<20],*S=buf,*T=S;
    return S==T&&(T=(S=buf)+fread(buf,1,1<<20,stdin),S==T)?EOF:*S++;
}
inline int read(){
    char c;int rec=0;
    while((c=C())<'0'||c>'9');
    while(c>='0'&&c<='9')rec=rec*10+c-'0',c=C();
    return rec;
}
char B[1<<20],*S=B;
inline void Out(int x){
	char stack[20],top=0;
	stack[++top]=' ';if(!x)stack[++top]='0';
	while(x)stack[++top]=x%10+'0',x/=10;
	while(top)*S++=stack[top--];return ;
}
int n,m,D,R[Maxn];
char ssr[Maxn];
int ans[Maxn];
struct Cp{
    double r,i;
    inline Cp operator+(Cp x){return (Cp){r+x.r,i+x.i};}
    inline Cp operator-(Cp x){return (Cp){r-x.r,i-x.i};}
    inline Cp operator*(Cp x){return (Cp){r*x.r-i*x.i,r*x.i+i*x.r};}    
}a[Maxn],b[Maxn],temp[Maxn];
inline void Fft(Cp *x,int f){
    for(int i=0;i<n;++i)temp[i]=x[R[i]];
    for(int i=0;i<n;++i)x[i]=temp[i];
    temp[0]=(Cp){1,0};
    for(int s=2;s<=n;s<<=1){
        Cp wn=(Cp){cos(2*pi/s),f*sin(2*pi/s)};
        for(int j=1;j<(s>>1);++j)temp[j]=temp[j-1]*wn;
        for(int k=0;k<n;k+=s){
            Cp t,u;
            for(int j=0;j<(s>>1);++j){
                t=temp[j]*x[k+j+(s>>1)];
                u=x[k+j];
                x[k+j]=u+t;x[k+j+(s>>1)]=u-t;
            }
        }
    }
    if(f==-1)for(int i=0;i<=n;++i)x[i].r/=n;
    return ;
}
int main(){
    n=read();m=read();
    for(int i=0,x;i<=n;++i)x=read(),a[i].r=x;
    for(int i=0,x;i<=m;++i)x=read(),b[i].r=x;
    m+=n;for(n=1;n<=m;n<<=1,++D);
    for(int i=0;i<n;++i)R[i]=(R[i>>1]>>1)|((i&1)<<(D-1));
    Fft(a,1);Fft(b,1);
    for(int i=0;i<=n;++i)a[i]=a[i]*b[i];
    Fft(a,-1);
    for(int i=0;i<=m;++i)Out((int)(a[i].r+0.5));
    fwrite(B,1,S-B,stdout);
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #112.26 us48 KBAcceptedScore: 0

Subtask #1 Testcase #229.237 ms15 MB + 900 KBAcceptedScore: 100

Subtask #1 Testcase #312.195 ms7 MB + 288 KBAcceptedScore: 0

Subtask #1 Testcase #412.235 ms7 MB + 268 KBAcceptedScore: 0

Subtask #1 Testcase #513.16 us48 KBAcceptedScore: 0

Subtask #1 Testcase #612.78 us48 KBAcceptedScore: 0

Subtask #1 Testcase #712.27 us48 KBAcceptedScore: 0

Subtask #1 Testcase #828.598 ms15 MB + 524 KBAcceptedScore: 0

Subtask #1 Testcase #928.474 ms15 MB + 524 KBAcceptedScore: 0

Subtask #1 Testcase #1027.811 ms15 MB + 88 KBAcceptedScore: 0

Subtask #1 Testcase #1129.377 ms16 MB + 40 KBAcceptedScore: 0

Subtask #1 Testcase #1226.347 ms14 MB + 188 KBAcceptedScore: 0

Subtask #1 Testcase #1312.45 us48 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:18:46 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠