提交记录 9024


用户 题目 状态 得分 用时 内存 语言 代码长度
bestwyj 1002i. 【模板题】多项式乘法 Accepted 100 44.789 ms 6560 KB C++11 1.74 KB
提交时间 评测时间
2019-04-04 10:07:21 2020-08-01 01:29:34
#include<set>
#include<map>
#include<cmath>
#include<cstdio>
#include<bitset>
#include<vector>
#include<cstring>
#include<algorithm>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;

const int N=4194310,P=998244353;

struct IO_tp
{
	static const int Sbuf=1<<21;
	char buf[Sbuf], *S, *T, c; int f;
	#define gc() (S==T?(T=(S=buf)+fread(buf,1,sizeof(buf),stdin),(S==T?EOF:*S++)):*S++)
	template<class I>
	inline IO_tp& operator >> (I &x)
	{
		for(f=1, c=gc(); c<'0'||c>'9'; c=gc()) if(c=='-') f=-1;
		for(x=0; c>='0'&&c<='9'; c=gc()) x=x*10+(c^48); x*=f;
		return *this;
	}
}io;

char out[N],*O=out,qu[50];

inline void print(int x)
{
	int s=0;
	if(!x) *O++='0';
	while(x) qu[++s]=x%10+'0',x/=10;
	while(s) *O++=qu[s--];
}

int fpow(int a,int b)
{
	ll w(1),o(a);
	while(b)
	{
		if(b&1)w=w*o%P;
		o=o*o%P;
		b>>=1;
	}
	return w;
}

const int G=2333333,iG=fpow(G,P-2);

int n,m,A[N],B[N],L,U,h[N];

void NTT(int*f,int T)
{
	int w,wn,x,y;
	for(int i=0; i<U; i++)
		if(i<h[i])
			swap(f[i],f[h[i]]);
	for(int l=1; l<U; l<<=1)
	{
		wn=fpow(T>0?G:iG,(P-1)/(l<<1));
		for(int i=0; i<U; i+=l<<1)
		{
			w=1;
			for(int j=i; j<i+l; j++)
			{
				x=f[j];
				y=(ll)f[j+l]*w%P;
				f[j]=(x+y)%P;
				f[j+l]=(x+P-y)%P;
				w=(ll)w*wn%P;
			}
		}
	}
	if(T<0)
	{
		w=fpow(U,P-2);
		for(int i=0; i<U; i++)
			f[i]=(ll)f[i]*w%P;
	}
}

int main()
{
	io>>n>>m;
	for(int i=0; i<=n; i++)io>>A[i];
	for(int i=0; i<=m; i++)io>>B[i];
	for(U=1; U<=n+m; U<<=1)L++;
	for(int i=0; i<U; i++)
		h[i]=(h[i>>1]>>1)|((i&1)<<(L-1));
	NTT(A, 1);
	NTT(B, 1);
	for(int i=0; i<U; i++)
		A[i]=(ll)A[i]*B[i]%P;
	NTT(A,-1);
	for(int i=0; i<=n+m; i++)
	{
		print(A[i]);
		*O++=' ';
	}
	fwrite(out,1,O-out,stdout);
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #18.08 us32 KBAcceptedScore: 0

Subtask #1 Testcase #244.521 ms6 MB + 256 KBAcceptedScore: 100

Subtask #1 Testcase #320.102 ms2 MB + 276 KBAcceptedScore: 0

Subtask #1 Testcase #420.128 ms2 MB + 256 KBAcceptedScore: 0

Subtask #1 Testcase #59.6 us32 KBAcceptedScore: 0

Subtask #1 Testcase #69 us32 KBAcceptedScore: 0

Subtask #1 Testcase #78.26 us32 KBAcceptedScore: 0

Subtask #1 Testcase #843.779 ms5 MB + 676 KBAcceptedScore: 0

Subtask #1 Testcase #943.794 ms5 MB + 676 KBAcceptedScore: 0

Subtask #1 Testcase #1043.122 ms5 MB + 72 KBAcceptedScore: 0

Subtask #1 Testcase #1144.789 ms6 MB + 416 KBAcceptedScore: 0

Subtask #1 Testcase #1241.864 ms4 MB + 172 KBAcceptedScore: 0

Subtask #1 Testcase #137.26 us32 KBAcceptedScore: 0


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