标签:opera ati inf har swa lan main lld out
#include <cstdio>
#include <algorithm>
using namespace std;
#define R register
#define LL long long
const int inf=0x3f3f3f3f;
const int MAXN=4e6+10;
inline int read() {
char a=getchar(); int x=0,f=1;
for(;a>‘9‘||a<‘0‘;a=getchar()) if(a==‘-‘) f=-1;
for(;a>=‘0‘&&a<=‘9‘;a=getchar()) x=x*10+a-‘0‘;
return x*f;
}
namespace Operation {
const int P=998244353;
const int G=3;
const int Gi=332748118;
int bit,lim;
int rev[MAXN];
inline LL qpow(LL x,LL k) {
LL res=1;
while(k) {
if(k&1) res=res*x%P;
x=x*x%P; k>>=1;
}
return res%P;
}
inline void NTT(LL *A,int type) {
for(R int i=0;i<lim;i++) if(i<rev[i]) swap(A[i],A[rev[i]]);
for(R int dep=1;dep<lim;dep<<=1) {
LL Wn=qpow( type==1 ? G : Gi, (P-1)/ (dep<<1) );
for(R int j=0,len=dep<<1 ;j<lim; j+=len ) {
LL w=1;
for(R int k=0; k<dep; k++ ,w=w*Wn%P) {
int x=A[j+k],y=A[j+dep+k]*w%P;
A[j+k]=(x+y)%P;
A[j+k+dep]=(x-y+P)%P;
}
}
}
if(type==-1) {
int inv=qpow(lim,P-2);
for(R int i=0;i<lim;i++) A[i]=A[i]*inv%P;
}
}
inline void Turn(LL *A,LL *B,int n,int m) {
lim=1; bit=0;
while(lim<=n+m) lim<<=1,bit++;
for(R int i=0;i<lim;i++) rev[i]=(rev[i>>1]>>1)|((i&1)<<(bit-1));
NTT(A,1); NTT(B,1);
for(R int i=0;i<lim;i++) A[i]=A[i]*B[i]%P;
NTT(A,-1);
}
}
int n,m;
LL f[MAXN],g[MAXN];
int main() {
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
n=read(); m=read();
for(R int i=0;i<=n;i++) f[i]=read();
for(R int i=0;i<=m;i++) g[i]=read();
Operation::Turn(f,g,n,m);
for(R int i=0;i<=n+m;i++) printf("%lld ",f[i]);
return 0;
}
标签:opera ati inf har swa lan main lld out
原文地址:https://www.cnblogs.com/HN-wrp/p/HN-wrp.html