提交记录 8560


用户 题目 状态 得分 用时 内存 语言 代码长度
OI_berbi 1002i. 【模板题】多项式乘法 Runtime Error 0 74.255 ms 4284 KB C++ 1.17 KB
提交时间 评测时间
2019-02-25 19:59:24 2020-08-01 01:21:17
#include <bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
using namespace std;
namespace NTT {
	const int N=270000,P=998244353;
	int n,A[N],B[N],R[N];
	int Pow (int x,int k) {
		int r=1;
		while (k) {
			if (k&1) r=1LL*r*x%P;
			x=1LL*x*x%P; k>>=1;
		}
		return r;
	}
	void DFT (int *A,int o) {
		For(i,0,n-1) if (i<R[i]) swap(A[i],A[R[i]]);
		for(int i=1;i<n;i<<=1) {
			int wn=Pow(3,(P-1)/i>>1);
			if (o) wn=Pow(wn,P-2);
			for(int j=0;j<n;j+=i+i) {
				int w=1;
				For(k,0,i-1) {
					int t=1LL*w*A[j+k+i]%P;
					A[j+k+i]=(A[j+k]-t+P)%P;
					A[j+k]=(A[j+k]+t)%P;
					w=1LL*w*wn%P;
				}
			}
		}
		if (o) {
			int x=Pow(n,P-2);
			For(i,0,n-1) A[i]=1LL*A[i]*x%P;
		}
	}
	void Mul (int *_A,int a,int *_B,int b) {
		For(i,0,a-1) A[i]=_A[i];
		For(i,0,b-1) B[i]=_B[i];
		for(n=1;n<a+b;n<<=1);
		For(i,0,n-1) R[i]=(R[i>>1]>>1)|((i&1)*(n/2));
		DFT(A,0),DFT(B,0);
		For(i,0,n-1) _A[i]=1LL*A[i]*B[i]%P;
		DFT(_A,1);
	}
}
using NTT::Mul;

const int N=100007;
int A[N],B[N],a,b;
int main () {
	scanf("%d%d",&a,&b),++a,++b;
	For(i,0,a-1) scanf("%d",&A[i]);
	For(i,0,b-1) scanf("%d",&B[i]);
	Mul(A,a,B,b);
	For(i,0,a+b-2) printf("%d ",A[i]);
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #137.52 us56 KBAcceptedScore: 0

Subtask #1 Testcase #232.697 ms3 MB + 820 KBRuntime ErrorScore: 0

Subtask #1 Testcase #315.532 ms2 MB + 308 KBRuntime ErrorScore: 0

Subtask #1 Testcase #415.525 ms1 MB + 948 KBRuntime ErrorScore: 0

Subtask #1 Testcase #542.7 us56 KBAcceptedScore: 0

Subtask #1 Testcase #640.17 us56 KBAcceptedScore: 0

Subtask #1 Testcase #739.56 us56 KBAcceptedScore: 0

Subtask #1 Testcase #831.948 ms3 MB + 820 KBRuntime ErrorScore: 0

Subtask #1 Testcase #931.922 ms3 MB + 692 KBRuntime ErrorScore: 0

Subtask #1 Testcase #1031.214 ms3 MB + 692 KBRuntime ErrorScore: 0

Subtask #1 Testcase #1132.694 ms3 MB + 820 KBRuntime ErrorScore: 0

Subtask #1 Testcase #1274.255 ms4 MB + 188 KBAcceptedScore: 0

Subtask #1 Testcase #1336.48 us56 KBAcceptedScore: 0


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