提交记录 16943


用户 题目 状态 得分 用时 内存 语言 代码长度
Minion 1002i. 【模板题】多项式乘法 Accepted 100 73.56 ms 6680 KB C++11 1.36 KB
提交时间 评测时间
2021-11-09 07:20:24 2021-11-09 07:20:27
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define M 10
#define N1 2100010
#define P 998244353
#define g 3
using namespace std;
typedef long long  ll;
int n,m,N,rev[N1],lg;
char s[1000010],stk[10];
ll ans[N1],a[N1],b[N1];
ll ksm(ll x,ll y,ll p)
{
	ll res = 1;
	while(y > 0)
	{
		if(y & 1) res = res * x % p;
		x = x * x % p;
		y = y >> 1;
	}
	return res;
}
void NTT(ll a[],int xs)
{
	int l = 1;
	for(int i = 0;i < N;i++)
	{
		rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << lg - 1);
		if(i < rev[i])
		{
			ll t = a[i];
			a[i] = a[rev[i]];
			a[rev[i]] = t;
		}
	}
	int mi = 1;
	for(int i = 1;i <= lg;i++)
	{
		ll w = ksm(g,(P - 1) >> i,P);
		if(xs == -1) w = ksm(w,P - 2,P);
		for(int j = 0;j < N;j += (1 << i))
		{
			ll w1 = 1;
			for(int k = 0;k < mi;k++)
			{
				ll t = w1 * a[j + k + mi] % P,u = a[j + k];
				a[j + k] = (u + t) % P;
				a[j + k + mi] = (u - t + P) % P;
				w1 = w1 * w % P;
			}
		}
		mi = (mi << 1) % P;
	}
	if(xs == -1)
	{
		ll ny = ksm(N,P - 2,P);
		for(int i = 0;i < N;i++) a[i] = a[i] * ny % P;
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i = 0;i <= n;i++) scanf("%lld",&a[i]);
	for(int i = 0;i <= m;i++) scanf("%lld",&b[i]);
	N = 1;
	while(N <= m + n)
	{
		N = N << 1;
		lg++;
	}
	NTT(a,1);
	NTT(b,1);
	for(int i = 0;i < N;i++) a[i] = a[i] * b[i] % P;
	NTT(a,-1);
	for(int i = 0;i <= n + m;i++) printf("%lld ",a[i]);
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #111.16 us28 KBAcceptedScore: 0

Subtask #1 Testcase #273.096 ms6 MB + 456 KBAcceptedScore: 100

Subtask #1 Testcase #334.285 ms2 MB + 820 KBAcceptedScore: 0

Subtask #1 Testcase #434.431 ms2 MB + 808 KBAcceptedScore: 0

Subtask #1 Testcase #512.17 us28 KBAcceptedScore: 0

Subtask #1 Testcase #611.51 us28 KBAcceptedScore: 0

Subtask #1 Testcase #711.39 us28 KBAcceptedScore: 0

Subtask #1 Testcase #867.298 ms6 MB + 188 KBAcceptedScore: 0

Subtask #1 Testcase #967.263 ms6 MB + 188 KBAcceptedScore: 0

Subtask #1 Testcase #1061.327 ms5 MB + 944 KBAcceptedScore: 0

Subtask #1 Testcase #1173.56 ms6 MB + 536 KBAcceptedScore: 0

Subtask #1 Testcase #1273.295 ms5 MB + 416 KBAcceptedScore: 0

Subtask #1 Testcase #139.99 us28 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-03-18 08:33:37 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠