提交记录 5114


用户 题目 状态 得分 用时 内存 语言 代码长度
zhaimingshuzms 1002i. 【模板题】多项式乘法 Accepted 100 57.021 ms 5136 KB C++ 1.24 KB
提交时间 评测时间
2018-08-06 20:00:40 2020-08-01 00:11:11
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const int P=262144;
const int M=998244353;
int m,n;
int a[P],w[P],b[P],rev[P];
inline int D(int x){
    return x>=M?x-M:x;
}
inline int U(int x){
    return x<0?x+M:x; 
}
inline int fp(int x,int y){
    int ret=1; for (; y; y>>=1,x=(ll)x*x%M) if (y&1) ret=(ll)ret*x%M; return ret;
}
void NTT(int *a,int n){
    for (int i=0; i<n; ++i) if (rev[i]>i) swap(a[i],a[rev[i]]);
    for (int i=1; i<n; i<<=1){
        w[0]=1; w[1]=fp(3,(M-1)/(i<<1));
        for (int j=2; j<i; ++j) w[j]=(ll)w[j-1]*w[1]%M;
        for (int j=0; j<n; j+=(i<<1))
        for (int k=j; k<j+i; ++k){
            int x=a[k],y=(ll)w[k-j]*a[k+i]%M;
            a[k]=D(x+y);
            a[k+i]=U(x-y);
        }
    }
}
#define fuc(a,b,c) for (int i=0; i<u; ++i) c[i]=(ll)a[i]*b[i]%M
int main(){
    scanf("%d%d",&m,&n); ++m; ++n;
    for (int i=0; i<m; ++i) scanf("%d",&a[i]);
	for (int i=0; i<n; ++i) scanf("%d",&b[i]); 
    int u,c=0; for (u=1; u<n+m-1; u<<=1,++c);
    for (int i=0; i<u; ++i) rev[i]=rev[i>>1]>>1|((i&1)<<(c-1));
    NTT(a,u); NTT(b,u);
	fuc(a,b,a);
	reverse(a+1,a+u);
	NTT(a,u);
	int ni=fp(u,M-2); 
	for (int i=0; i<u; ++i) a[i]=(ll)a[i]*ni%M;
	for (int i=0; i<=n+m-2; ++i) printf("%d ",a[i]); 
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #110.79 us32 KBAcceptedScore: 0

Subtask #1 Testcase #256.704 ms4 MB + 960 KBAcceptedScore: 100

Subtask #1 Testcase #326.026 ms2 MB + 56 KBAcceptedScore: 0

Subtask #1 Testcase #425.96 ms2 MB + 44 KBAcceptedScore: 0

Subtask #1 Testcase #512.69 us32 KBAcceptedScore: 0

Subtask #1 Testcase #612.14 us32 KBAcceptedScore: 0

Subtask #1 Testcase #710.81 us32 KBAcceptedScore: 0

Subtask #1 Testcase #850.632 ms4 MB + 692 KBAcceptedScore: 0

Subtask #1 Testcase #950.61 ms4 MB + 692 KBAcceptedScore: 0

Subtask #1 Testcase #1044.925 ms4 MB + 424 KBAcceptedScore: 0

Subtask #1 Testcase #1156.76 ms5 MB + 16 KBAcceptedScore: 0

Subtask #1 Testcase #1257.021 ms3 MB + 920 KBAcceptedScore: 0

Subtask #1 Testcase #139.2 us28 KBAcceptedScore: 0


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