提交记录 17050


用户 题目 状态 得分 用时 内存 语言 代码长度
TQX 1002i. 【模板题】多项式乘法 Accepted 100 18.728 ms 9656 KB C++ 4.44 KB
提交时间 评测时间
2021-11-30 18:20:13 2021-11-30 18:20:17
#include<bits/stdc++.h>
using namespace std;
const int N=(1<<21)+20;
const int mod=998244353;
typedef vector<int> vec;
typedef unsigned long long ull;

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;
using IO::nc;
//IObuff没判负数 

namespace Math{
	inline int add(int x,int y){return (x+y>=mod)?x+y-mod:x+y;}
	inline int dec(int x,int y){return (x-y<0)?x-y+mod:x-y;}
	inline void inc(int &x,int y){x=add(x,y);}
	inline void rec(int &x,int y){x=dec(x,y);}
	inline int ksm(int x,int y){
		int ret=1;
		for(;y;y>>=1,x=1ll*x*x%mod) if(y&1) ret=1ll*ret*x%mod;
		return ret; 
	}
	int iv[N],tp;
	inline void init_inv(int n){
		if(!tp){iv[0]=iv[1]=1;tp=2;}
		for(;tp<=n;++tp) iv[tp]=1ll*(mod-mod/tp)*iv[mod%tp]%mod;
	}
}
using namespace Math;

namespace Cipolla{
	int I,fl=0;
	mt19937 rnd(time(0));
	struct pt{int a,b;pt(int _a=0,int _b=0){a=_a;b=_b;}};
	inline pt operator *(pt x,pt y){
		pt ret;
		ret.a=add(1ll*x.a*y.a%mod,1ll*x.b*y.b%mod*I%mod);
		ret.b=add(1ll*x.a*y.b%mod,1ll*x.b*y.a%mod);
		return ret;
	}
	inline bool check(int x){return ksm(x,(mod-1)/2)==1;}
	inline int random(){return rnd()%mod;}
	inline pt qpow(pt a,int b){
		pt ret=pt(1,0);
		for(;b;a=a*a,b>>=1) if(b&1) ret=ret*a;
		return ret;
	}
	inline int cipolla(int n){
		if(!check(n)) return 0;
		int a=random();
		while(!a||check(dec(1ll*a*a%mod,n))) a=random();
		I=dec(1ll*a*a%mod,n);
		int ans=qpow(pt(a,1),(mod+1)/2).a;
		return min(ans,(int)mod-ans);
	}
}
using namespace Cipolla;

struct poly{
	vec v;
	inline poly(int w=0):v(1){v[0]=w;}
	inline poly(const vec&w):v(w){}
		
	inline int operator [](int x)const{return x>=v.size()?0:v[x];}
	inline int& operator [](int x){if(x>=v.size()) v.resize(x+1);return v[x];}
	inline int size(){return v.size();}
	inline void resize(int x){v.resize(x);}
	inline void read(int n){v.resize(n);for(int i=0;i<n;++i) v[i]=Rint;}
	inline void print(int n)const{for(int i=0;i<n-1;++i) put(operator[](i),' ');put(operator[](n-1),'\n');}
	
	inline poly slice(int len)const{
		if(len<=v.size()) return vec(v.begin(),v.begin()+len);
		vec ret(v);ret.resize(len);
		return ret;
	}
	inline poly operator *(const int &x)const{
		poly ret(v);
		for(int i=0;i<v.size();++i) ret[i]=1ll*ret[i]*x%mod; 
		return ret;
	}
	inline poly operator +(const poly &x)const{
		vec ret(max(v.size(),x.v.size()));
		for(int i=0;i<v.size();++i) ret[i]=add(v[i],x[i]);
		return ret;
	}
	inline poly operator -(const poly &x)const{
		vec ret(max(v.size(),x.v.size()));
		for(int i=0;i<v.size();++i) ret[i]=dec(v[i],x[i]);
		return ret;
	}
};


int Wn[N<<1],lg[N],r[N],tot;
inline void init_poly(int n){
	int p=1;while(p<=n)p<<=1;
	for(int i=2;i<=p;++i) lg[i]=lg[i>>1]+1;
	for(int i=1;i<p;i<<=1){
		int wn=ksm(3,(mod-1)/(i<<1));
		Wn[++tot]=1;
		for(int j=1;j<i;++j) ++tot,Wn[tot]=1ll*Wn[tot-1]*wn%mod;
	}
}
inline void init_pos(int lim){
	int len=lg[lim]-1;
	for(int i=0;i<lim;++i) r[i]=(r[i>>1]>>1)|((i&1)<<len);
}

ull fr[N];
const ull Mod=998244353;
inline void NTT(int *f,int lim,int tp){
	for(int i=0;i<lim;++i) fr[i]=f[r[i]];
	for(int mid=1;mid<lim;mid<<=1){
		for(int len=mid<<1,l=0;l+len-1<lim;l+=len){
			for(int k=l;k<l+mid;++k){
				ull w1=fr[k],w2=fr[k+mid]*Wn[mid+k-l]%Mod;
				fr[k]=w1+w2;fr[k+mid]=w1+Mod-w2; 
			}
		}
	}
	for(int i=0;i<lim;++i) f[i]=fr[i]%Mod;
	if(!tp){
		reverse(f+1,f+lim);
		int iv=ksm(lim,mod-2);
		for(int i=0;i<lim;++i) f[i]=1ll*f[i]*iv%mod;
	}
}
inline poly to_poly(int *a,int n){
	poly ret;
	ret.resize(n);
	memcpy(ret.v.data(),a,n<<2);
	return ret;
}

int n,m;
int f[N],g[N];
inline void mul(){
	int rec=n+m-1;
	int len=lg[rec],lim=1<<len+1;
	init_pos(lim);
	NTT(f,lim,1);NTT(g,lim,1);
	for(int i=0;i<lim;++i) f[i]=1ll*f[i]*g[i]%mod;
	NTT(f,lim,0);
	for(int i=0;i<rec;++i) put(f[i],' ');
}

int main(){
	n=Rint+1;m=Rint+1;
	for(int i=0;i<n;++i) f[i]=Rint;
	for(int i=0;i<m;++i) g[i]=Rint;
	init_poly(n+m);
	mul();
	IO::flush();
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #138.77 us80 KBAcceptedScore: 0

Subtask #1 Testcase #218.571 ms9 MB + 360 KBAcceptedScore: 0

Subtask #1 Testcase #37.965 ms4 MB + 328 KBAcceptedScore: 100

Subtask #1 Testcase #48.019 ms4 MB + 304 KBAcceptedScore: 0

Subtask #1 Testcase #540.87 us80 KBAcceptedScore: 0

Subtask #1 Testcase #639.42 us80 KBAcceptedScore: 0

Subtask #1 Testcase #738.82 us80 KBAcceptedScore: 0

Subtask #1 Testcase #817.86 ms9 MB + 24 KBAcceptedScore: 0

Subtask #1 Testcase #917.869 ms9 MB + 24 KBAcceptedScore: 0

Subtask #1 Testcase #1017.184 ms8 MB + 712 KBAcceptedScore: 0

Subtask #1 Testcase #1118.728 ms9 MB + 440 KBAcceptedScore: 0

Subtask #1 Testcase #1216.013 ms8 MB + 228 KBAcceptedScore: 0

Subtask #1 Testcase #1338.69 us80 KBAcceptedScore: 0


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