提交记录 13469


用户 题目 状态 得分 用时 内存 语言 代码长度
wasa855 1002i. 【模板题】多项式乘法 Accepted 100 51.549 ms 7228 KB C++ 2.32 KB
提交时间 评测时间
2020-08-05 10:36:20 2020-08-05 10:36:26
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define fir first
#define sec second
#define mod 998244353
#define G 3
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
int mul(int x,int y){return 1uLL*x*y%mod;}
int qpow(int x,int y)
{
	int ans=1;
	while(y)
	{
		if(y&1) ans=mul(ans,x);
		x=mul(x,x);
		y>>=1;
	}
	return ans;
}
int Inv(int x)
{
	return qpow(x,mod-2);
}
namespace Poly
{
	vector<int> rev,rt,one(1,1);
	vector<int> operator + (vector<int> a,vector<int> b)
	{
		int n=max(a.size(),b.size());
		a.resize(n),b.resize(n);
		for(int i=0;i<n;i++) a[i]=add(a[i],b[i]);
		return a;
	}
	vector<int> operator - (vector<int> a,vector<int> b)
	{
		int n=max(a.size(),b.size());
		a.resize(n),b.resize(n);
		for(int i=0;i<n;i++) a[i]=sub(a[i],b[i]);
		return a;
	}
	void init(int B)
	{
		int n=1<<B;
		rev.resize(n),rt.resize(n);
		for(int i=1;i<n;i++) rev[i]=(rev[i>>1]>>1)|((i&1)<<(B-1));
		for(int mid=1;mid<n;mid<<=1)
		{
			int w=qpow(G,(mod-1)/(mid<<1));
			rt[mid]=1;
			for(int i=1;i<=mid;i++) rt[mid+i]=mul(rt[mid+i-1],w);
		}
	}
	void NTT(vector<int> &a,int B)
	{
		int n=1<<B;
		for(int i=0;i<n;i++) if(rev[i]>i) swap(a[i],a[rev[i]]);
		for(int mid=1;mid<n;mid<<=1)
		{
			for(int i=0;i<n;i+=(mid<<1))
			{
				for(int j=0;j<mid;j++)
				{
					int x=a[i+j],y=mul(a[i+j+mid],rt[j+mid]);
					a[i+j]=add(x,y),a[i+j+mid]=sub(x,y);
				}
			}
		}
	}
	vector<int> operator * (vector<int> a,vector<int> b)
	{
		int B=0,n=a.size()+b.size()-1;
		while((1<<B)<n) B++;
		a.resize(1<<B),b.resize(1<<B);
		init(B);
		NTT(a,B),NTT(b,B);
		for(int i=0;i<(1<<B);i++) a[i]=mul(a[i],b[i]);
		reverse(a.begin()+1,a.end());
		NTT(a,B);
		a.resize(n);
		int In=Inv(1<<B);
		for(int i=0;i<n;i++) a[i]=mul(a[i],In);
		return a;
	}
};
using Poly::operator *;
signed main()
{
	vector<int> a,b;
	a.resize(read()+1),b.resize(read()+1);
	for(int i=0;i<(int)a.size();i++) a[i]=read();
	for(int i=0;i<(int)b.size();i++) b[i]=read();
	a=a*b;
	for(int i=0;i<(int)a.size();i++) printf("%d ",a[i]);
	cout<<"\n";
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #137.83 us36 KBAcceptedScore: 0

Subtask #1 Testcase #250.718 ms6 MB + 1004 KBAcceptedScore: 0

Subtask #1 Testcase #323.116 ms3 MB + 80 KBAcceptedScore: 100

Subtask #1 Testcase #423.184 ms3 MB + 68 KBAcceptedScore: 0

Subtask #1 Testcase #538.4 us36 KBAcceptedScore: 0

Subtask #1 Testcase #637.89 us36 KBAcceptedScore: 0

Subtask #1 Testcase #736.8 us36 KBAcceptedScore: 0

Subtask #1 Testcase #845.463 ms6 MB + 468 KBAcceptedScore: 0

Subtask #1 Testcase #945.437 ms6 MB + 468 KBAcceptedScore: 0

Subtask #1 Testcase #1040.301 ms5 MB + 952 KBAcceptedScore: 0

Subtask #1 Testcase #1151.034 ms7 MB + 60 KBAcceptedScore: 0

Subtask #1 Testcase #1251.549 ms5 MB + 964 KBAcceptedScore: 0

Subtask #1 Testcase #1336.25 us36 KBAcceptedScore: 0


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