提交记录 17065


用户 题目 状态 得分 用时 内存 语言 代码长度
cyf 1002i. 【模板题】多项式乘法 Accepted 100 25.492 ms 21440 KB C++11 2.28 KB
提交时间 评测时间
2021-11-30 18:44:08 2021-11-30 18:44:13
#include <bits/stdc++.h>
#define maxn 600005
#define LL long long
#define mod 998244353
using namespace std;
int Wl,Wl2,w[maxn],lg[maxn],inv[maxn];
inline int Pow(int b, int k) { int r=1; for(;k;k>>=1,b=1ll*b*b%mod) if(k&1) r=1ll*r*b%mod; return r; }
inline void init(int n) {
	for(Wl=1;n>=Wl<<1;Wl<<=1) ;
	int pw=Pow(3,(mod-1)/(Wl2=Wl<<1));
	w[Wl]=inv[0]=inv[1]=1;
	for(int i=Wl+1;i<=Wl2;i++) w[i]=w[i-1]*1ll*pw%mod;
	for(int i=Wl-1;i>=1;i--) w[i]=w[i<<1];
	for(int i=2;i<=Wl2;i++) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod,lg[i]=lg[i>>1]+1;
}
inline int upd(int x) { return x+=x>>31&mod; }
inline void NTT(int *A, int n, int tp) {
	static int r[maxn]={};
	static unsigned LL ar[maxn]={};
	if(tp^1) reverse(A+1,A+n);
	for(int i=0;i<n;i++) r[i]=(r[i>>1]>>1|(i&1)<<lg[n]-1),ar[i]=upd(A[r[i]]);
	for(int L=1;L<n;L<<=1) for(int s=0,L2=L<<1;s<n;s+=L2)
	for(int k=s,x=L,t;x<L2;x++,k++) t=ar[k+L]*w[x]%mod,ar[k+L]=ar[k]-t+mod,ar[k]+=t;
	for(int i=0;i<n;i++) A[i]=ar[i]%mod;
	if(tp^1) for(int i=0;i<n;i++) A[i]=1ll*A[i]*inv[n]%mod;
}
#define Poly vector<int>
inline Poly Mul(Poly A,Poly B,int l=-1) {
	int n=A.size(),m=B.size(),N=(l==-1)?(n+m-1):l,M=1<<lg[N]+1;
	A.resize(M<<2); B.resize(M<<2);
	NTT(A.data(),M,1); NTT(B.data(),M,1);
	for(int i=0;i<M;i++) A[i]=1ll*A[i]*B[i]%mod;
	NTT(A.data(),M,-1); A.resize(N); return A;
}
inline int Init(int n) { int m; for(m=1;m<=n;m<<=1); init(m); return m; }
int n,m,k; Poly A,B;
namespace IO {
	inline char nc(){
		static char buf[500005],*p1=buf,*p2=buf;
		return p1==p2&&(p2=(p1=buf)+fread(buf,1,500000,stdin),p1==p2)?EOF:*p1++;
	}
	char out[500005],*pout=out,*eout=out+500000;
	inline void flush() { fwrite(out,1,pout-out,stdout),pout=out; }
	inline void pc(char c) { pout==eout&&(fwrite(out,1,500000,stdout),pout=out); (*pout++)=c; }
	template<typename T> inline void put(T x,char suf) {
		static char stk[40];int top=0; while(x) stk[top++]=x%10,x/=10;
		!top?pc('0'),0:0; while(top--) pc(stk[top]+'0'); pc(suf);
	}
	inline int read(){
		char ch=nc(); int sum=0; for(;ch<'0'||ch>'9';ch=nc());
		while(ch>='0'&&ch<='9')sum=(sum<<1)+(sum<<3)+ch-48,ch=nc();
		return sum;
	}
}
#define Rint IO::read()
using IO::put;
int main(){
	A.resize(n=Rint+1); B.resize(m=Rint+1);
	for(int i=0;i<n;i++) A[i]=Rint; for(int i=0;i<m;i++) B[i]=Rint;
	Init(n+m+233); A=Mul(A,B); for(int x:A) put(x,' '); IO::flush();
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #141.49 us64 KBAcceptedScore: 0

Subtask #1 Testcase #225.273 ms20 MB + 880 KBAcceptedScore: 0

Subtask #1 Testcase #310.486 ms10 MB + 68 KBAcceptedScore: 100

Subtask #1 Testcase #410.522 ms10 MB + 48 KBAcceptedScore: 0

Subtask #1 Testcase #543.14 us64 KBAcceptedScore: 0

Subtask #1 Testcase #641.23 us64 KBAcceptedScore: 0

Subtask #1 Testcase #740.76 us64 KBAcceptedScore: 0

Subtask #1 Testcase #824.56 ms20 MB + 280 KBAcceptedScore: 0

Subtask #1 Testcase #924.56 ms20 MB + 280 KBAcceptedScore: 0

Subtask #1 Testcase #1023.856 ms19 MB + 696 KBAcceptedScore: 0

Subtask #1 Testcase #1125.492 ms20 MB + 960 KBAcceptedScore: 0

Subtask #1 Testcase #1222.699 ms19 MB + 744 KBAcceptedScore: 0

Subtask #1 Testcase #1340.34 us64 KBAcceptedScore: 0


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