提交记录 17116


用户 题目 状态 得分 用时 内存 语言 代码长度
asd_a 1002i. 【模板题】多项式乘法 Accepted 100 18.979 ms 9132 KB C++11 4.05 KB
提交时间 评测时间
2021-11-30 20:56:45 2021-11-30 20:56:50
#pragma GCC optimize("-Ofast")
// #pragma GCC optimize("-fno-math-errno")
// #pragma GCC optimize("-funsafe-math-optimizations")
// #pragma GCC optimize("-freciprocal-math")
// #pragma GCC optimize("-fno-trapping-math")
// #pragma GCC optimize("-ffinite-math-only")
// #pragma GCC optimize("-fno-stack-protector")
#include<bits/stdc++.h>
namespace iobuff{
	const int len=1<<20;
	#ifdef DEBUG
		#define gc() getchar()
	#else
		char ibuf[len+5],*st=ibuf,*ed=ibuf;
		#define gc() (st==ed&&(ed=(st=ibuf)+fread(ibuf,1,len,stdin),st==ed)?EOF:*st++)
	#endif
	inline char gchar(){return gc();}
	template<typename T=int>
	inline T gint(T x=0){
		bool f=0;char c=gc();for(;c>'9'||c<'0';c=gc())f=c=='-';
		for(x=c-48,c=gc();c<='9'&&c>='0';c=gc())x=x*10+c-48;
		return f?-x:x;
	}
	#undef gc
	#ifdef DEBUG
		#define pc(x) putchar(x)
	#else
		char obuf[len+5],*p=obuf;
		#define pc(x) (p==obuf+len&&(fwrite(obuf,1,p-obuf,stdout),p=obuf),*p++=x)
		struct autoflush{~autoflush(){fwrite(obuf,1,p-obuf,stdout),p=obuf;}}autoflusher;
	#endif
	inline char pchar(char x){return pc(x),x;}
	template<typename T=int>
	inline void pint(T x){
		static char s[128];char *t=s;
		x<0&&(pc('-'),x=-x);
		do *t++='0'+x%10; while(x/=10);
		while(t!=s)pc(*--t);
	}
	#undef pc
}
using namespace std;
using iobuff::gint;
using iobuff::pint;
using namespace std;
const int mod=998244353,gen=3;
namespace math{
	// fast power , (x and ans) must in [-mod,mod], y must in [-mod+1,mod-1] 
	typedef int i32;
	typedef unsigned int u32;
	typedef long long i64;
	typedef unsigned long long u64;
	template<typename T=int>
	inline T fsp(i64 x,int y,i64 ans=1){
		for(y<0?y+=mod-1:0;y;y>>=1,x=x*x%mod)
			y&1?ans=ans*x%mod:0;
		return ans;
	}
	inline int lg(int x){return x==0?-1:__lg(x);}
	namespace fast_number_theory_transform{
		const int maxbit=22;
		const u32 modm2=mod+mod;
		template<class T>
		inline void butterfly(T* p,int bit) {
			for(u32 i=0,j=0;i<(1u<<bit);i++){
				// j=rev[i]=(rev[i>>1]>>1)^((i&1)<<(bit-1));
				if(i>j)swap(p[i],p[j]);
				for(u32 l=1u<<(bit-1);(j^=l)<l;l>>=1);
			}
		}
		u32 *_p0[maxbit+1],*_p1[maxbit+1];
		inline void prep(int bit){
			static int k=0;
			for(;k<bit;k++){
				u32 *p,*q,nl=1<<k;
				u64 g=fsp(3,mod>>(k+1));
				p=_p0[k]=new u32[nl<<1];q=p+nl;
				for(int i=p[0]=1;i<nl;i++)p[i]=p[i-1]*g%mod;
				butterfly(p,k);
				for(int i=0;i<nl;i++)q[i]=(u64(p[i])<<32)/mod;
				g=fsp(g,-1);
				p=_p1[k]=new u32[nl<<1];q=p+nl;
				for(int i=p[0]=1;i<nl;i++)p[i]=p[i-1]*g%mod;
				butterfly(p,k);
				for(int i=0;i<nl;i++)q[i]=(u64(p[i])<<32)/mod;
			}
		}inline u32 ntt_mul(u32 x,u64 p,u64 q){return x*p-(q*x>>32)*mod;}
		void ntt(u32* a,int bit,bool f=0){
			prep(bit);
			for(int k=bit;k-->0;){
				u32 *_p=_p0[bit-k-1],*_q=_p+(1<<(bit-k-1));
				u32 *_a0=a,*_a1=a+(1<<k);
				for(int i=0;i<1<<(bit-k-1);i++,_a0+=1<<(k+1),_a1+=1<<(k+1))
					for(int j=0;j<(1<<k);++j){
						u32 x=_a0[j]-(_a0[j]>=modm2)*modm2,y=ntt_mul(_a1[j],_p[i],_q[i]);
						_a0[j]=x+y;_a1[j]=x+modm2-y;
					}
			}for(int i=0;i<(1<<bit);i++){
				a[i]-=(a[i]>=modm2)*modm2;
				a[i]-=(a[i]>=mod)*mod;
			}if(f)butterfly(a,bit);
		}
		
		void intt(u32* a,int bit,bool f=0){
			prep(bit);
			if(f)butterfly(a,bit);
			for(int k=0;k<bit;k++){
				u32 *_p=_p1[bit-k-1],*_q=_p+(1<<(bit-k-1));
				u32 *_a0=a,*_a1=a+(1<<k);
				for(int i=0;i<1<<(bit-k-1);i++,_a0+=1<<(k+1),_a1+=1<<(k+1))
					for(int j=0;j<(1<<k);++j){
						u32 x=_a0[j],y=_a1[j];
						_a0[j]=x+y-(x+y>=modm2)*modm2;
						_a1[j]=ntt_mul(x+modm2-y,_p[i],_q[i]);
					}
			}
			u64 iv=mod;iv<<=bit;iv=(iv-mod+1)>>bit;
			for(int i=0;i<(1<<bit);i++)
				a[i]=a[i]*iv%mod;
		}
	}using fast_number_theory_transform::ntt;
	using fast_number_theory_transform::intt;
}
// using math::fsp;
using math::lg;
using math::ntt;
using math::intt;
int n,m;
unsigned a[262144],b[262144];
int main(){
// #ifndef DEBUG
// 	ios::sync_with_stdio(0);
// 	cin.tie(0);
// #endif
	n=gint();m=gint();
	for(int i=0;i<=n;i++)a[i]=gint();
	for(int i=0;i<=m;i++)b[i]=gint();
	int bit=lg(n+m)+1;
	ntt(a,bit);ntt(b,bit);
	for(int i=0;i<(1<<bit);i++)a[i]=1ll*a[i]*b[i]%mod;
	intt(a,bit);
	for(int i=0;i<=n+m;i++)pint(a[i]),iobuff::pchar(' ');
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #136.13 us52 KBAcceptedScore: 0

Subtask #1 Testcase #218.857 ms8 MB + 860 KBAcceptedScore: 100

Subtask #1 Testcase #37.878 ms3 MB + 808 KBAcceptedScore: 0

Subtask #1 Testcase #47.897 ms3 MB + 788 KBAcceptedScore: 0

Subtask #1 Testcase #538.7 us52 KBAcceptedScore: 0

Subtask #1 Testcase #636.12 us52 KBAcceptedScore: 0

Subtask #1 Testcase #737.48 us52 KBAcceptedScore: 0

Subtask #1 Testcase #818.167 ms8 MB + 524 KBAcceptedScore: 0

Subtask #1 Testcase #918.126 ms8 MB + 524 KBAcceptedScore: 0

Subtask #1 Testcase #1017.433 ms8 MB + 84 KBAcceptedScore: 0

Subtask #1 Testcase #1118.979 ms8 MB + 940 KBAcceptedScore: 0

Subtask #1 Testcase #1216.028 ms7 MB + 192 KBAcceptedScore: 0

Subtask #1 Testcase #1334.62 us52 KBAcceptedScore: 0


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