#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353,gen=3;
namespace math{
#ifdef DEBUG
#ifndef need_butterfly
#define need_butterfly
#endif
#endif
// 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++){
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){
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;
}
#ifdef need_butterfly
butterfly(a,bit);
#endif
}
void intt(u32* a,int bit){
prep(bit);
#ifdef need_butterfly
butterfly(a,bit);
#endif
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;
}
namespace polynormial{
typedef int i32;
typedef unsigned int u32;
typedef long long i64;
typedef unsigned long long u64;
typedef vector<u32> vec;
using math::lg;
using math::ntt;
using math::intt;
struct poly{
vec f;
poly(u32 x=0):f(1){f[0]=x;}
poly(int x):f(1){f[0]=x+((x>>31)&mod);}
poly(const vec& _f):f(_f){
}
poly(const vector<int>& _f){
f.resize(f.size());
for(int i=0;i<_f.size();i++){
f[i]=_f[i]+((_f[i]>>31)&mod);
}
}
poly(initializer_list<u32>_f):f(_f){
}
poly(initializer_list<int>_f){
f.resize(_f.size());
int i=0;for(int x:_f){
f[i++]=x+((x>>31)&mod);
}
}
inline void swap(poly& _f){f.swap(_f.f);}
inline int degree()const{return f.size()-1;}
inline void redegree(int x){return f.resize(x+1);}
inline void clear(){f.resize(1);f[0]=0;}
inline void shrink(){
int ndeg=f.size()-1;
while(ndeg>0&&f[ndeg]==0)ndeg--;
f.resize(ndeg+1);
}
// inline size_t size() const{return f.size();}
// inline void resize(int x){return f.resize(x);}
inline poly slice(int x)const{
if(x<0)return poly(0);
if(x<f.size())return vec(f.begin(),f.begin()+x+1);
poly _f(*this);return _f.f.resize(x+1),_f;
}
inline u32& operator [](int x){
#ifdef DEBUG
return f.at(x);
#else
return f[x];
#endif
}
inline u32 operator [](int x)const{
#ifdef DEBUG
return f.at(x);
#else
return f[x];
#endif
}
inline u32* data(){return f.data();}
inline const u32* data()const{return f.data();}
inline poly& operator +=(const poly& a){
f.resize(max(f.size(),a.f.size()));
for(int i=0;i<a.f.size();i++)f[i]=f[i]+a.f[i]-(f[i]+a.f[i]>=mod)*mod;
return *this;
}
inline poly& operator -=(const poly& a){
f.resize(max(f.size(),a.f.size()));
for(int i=0;i<a.f.size();i++)f[i]=f[i]-a.f[i]+(f[i]<a.f[i])*mod;
return *this;
}
inline poly operator +(const poly& a)const{return (poly(*this)+=a);}
inline poly operator -(const poly& a)const{return (poly(*this)-=a);}
inline poly& operator *=(const poly& a){ // redegree to this->degree()+a.degree()
int n=degree(),m=a.degree();
// if(min(f.size(),a.f.size())<16){
// f.resize(n+m+1);
// for(int i=n+m;i>=0;i--){
// f[i]=1ll*f[i]*a.f[0]%mod;
// for(int j=max(1,i-n);j<=m&&j<=i;j++)
// f[i]=(f[i]+1ll*f[i-j]*a.f[j])%mod;
// }return *this;
// }
vec _f(a.f);
int bit=lg(n+m)+1;
f.resize(1<<bit);_f.resize(1<<bit);
ntt(f.data(),bit);ntt(_f.data(),bit);
for(int i=0;i<(1<<bit);i++)f[i]=1ll*f[i]*_f[i]%mod;
intt(f.data(),bit);f.resize(n+m+1);
return *this;
}
inline poly operator *(const poly& a)const{return (poly(*this)*=a);}
};
ostream& operator <<(ostream& out,const poly& x){
out<<x.f[0];
for(int i=1;i<x.f.size();i++)out<<' '<<x.f[i];
return out;
}
}
// using math::fsp;
using polynormial::poly;
int n,m;
unsigned a[262144],b[262144];
int main(){
#ifndef DEBUG
ios::sync_with_stdio(0);
cin.tie(0);
#endif
cin>>n>>m;
for(int i=0;i<=n;i++)cin>>a[i];
for(int i=0;i<=m;i++)cin>>b[i];
cout<<(poly(vector<unsigned>(a,a+n+1))*=poly(vector<unsigned>(b,b+m+1)))<<endl;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Subtask #1 Testcase #1 | 43.94 us | 68 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #2 | 42.524 ms | 9 MB + 420 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #3 | 19.353 ms | 4 MB + 512 KB | Accepted | Score: 100 | 显示更多 |
| Subtask #1 Testcase #4 | 19.257 ms | 4 MB + 112 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #5 | 46.03 us | 68 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #6 | 43.81 us | 68 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #7 | 44.44 us | 68 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #8 | 38.272 ms | 9 MB + 4 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #9 | 38.211 ms | 8 MB + 896 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #10 | 34.053 ms | 8 MB + 352 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #11 | 43.538 ms | 9 MB + 500 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #12 | 39.065 ms | 8 MB + 380 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #13 | 42.5 us | 68 KB | Accepted | Score: 0 | 显示更多 |