提交记录 12576


用户 题目 状态 得分 用时 内存 语言 代码长度
BilyHurington 1002i. 【模板题】多项式乘法 Accepted 100 53.917 ms 8756 KB C++ 1.90 KB
提交时间 评测时间
2020-04-21 11:11:03 2020-08-01 02:56:27
/*
 * @Author: BilyHurington
 * @Date: 2020-04-18 18:20:10
 * @LastEditors: BilyHurington
 * @LastEditTime: 2020-04-20 10:11:46
 */
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353,gen=3;
namespace Polynomial{
    long long W[800010];
    int rev[800010],abc[800010];
    inline int mi(int x,int y){return x>=y?x-y:x-y+mod;}
    inline int pl(int x,int y){x+=y;return x>=mod?x-mod:x;}
    inline int fast_pow(int x,int k){
        long long ans=1;
        while(k){
            if(k&1) ans=(ans*x)%mod;
            x=(x*(long long)x)%mod;
            k>>=1;
        }
        return ans;
    }
    void init(int n){
        long long tmp;
        for(int i=1;i<n;i<<=1){
            W[i]=1;tmp=fast_pow(3,(mod-1)/2/i);
            for(int j=1;j<=i-1;j++) W[i+j]=tmp*W[i+j-1]%mod;
        }
        for(int i=1;i<=n;i<<=1){
		    for(int j=1;j<i;++j) rev[i+j]=rev[i+(j>>1)]>>1|j%2*i/2;
    	}
    }
    void NTT(int *a,int len,bool tag){
        for(int i=0;i<len;i++) abc[i]=a[rev[i+len]];
        for(int i=1;i<len;i<<=1){
            for(int j=0;j<len;j+=i<<1){
                for(int k=0;k<i;k++){
                    int t=abc[i+j+k]*W[i+k]%mod;
                    abc[i+j+k]=mi(abc[j+k],t);
                    abc[j+k]=pl(abc[j+k],t);
                }
            }
        }
        if(tag){
            reverse(abc+1,abc+len);
            for(int i=0,inv=fast_pow(len,mod-2);i<len;i++) a[i]=abc[i]*(long long)inv%mod;
        }
        else for(int i=0;i<len;i++) a[i]=abc[i];
    }
}
int n,m,a[400010],b[400010];
int main(){
    Polynomial::init(262144);
    scanf("%d %d",&n,&m);
    for(int i=0;i<=n;i++) scanf("%d",&a[i]);
    for(int i=0;i<=m;i++) scanf("%d",&b[i]);
    int t;
    for(t=1;t<n+m+2;t<<=1);
    Polynomial::NTT(a,t,0);
    Polynomial::NTT(b,t,0);
    for(int i=0;i<=t;i++) a[i]=a[i]*(long long)b[i]%mod;
    Polynomial::NTT(a,t,1);
    for(int i=0;i<=n+m;i++) printf("%d ",a[i]);
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #11.841 ms4 MB + 56 KBAcceptedScore: 0

Subtask #1 Testcase #253.463 ms8 MB + 484 KBAcceptedScore: 100

Subtask #1 Testcase #325.436 ms5 MB + 848 KBAcceptedScore: 0

Subtask #1 Testcase #425.412 ms5 MB + 836 KBAcceptedScore: 0

Subtask #1 Testcase #51.843 ms4 MB + 56 KBAcceptedScore: 0

Subtask #1 Testcase #61.843 ms4 MB + 56 KBAcceptedScore: 0

Subtask #1 Testcase #71.842 ms4 MB + 56 KBAcceptedScore: 0

Subtask #1 Testcase #847.859 ms8 MB + 216 KBAcceptedScore: 0

Subtask #1 Testcase #947.81 ms8 MB + 216 KBAcceptedScore: 0

Subtask #1 Testcase #1042.157 ms7 MB + 972 KBAcceptedScore: 0

Subtask #1 Testcase #1153.807 ms8 MB + 564 KBAcceptedScore: 0

Subtask #1 Testcase #1253.917 ms7 MB + 444 KBAcceptedScore: 0

Subtask #1 Testcase #131.84 ms4 MB + 56 KBAcceptedScore: 0


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