#include<bits/stdc++.h>
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 long long i64;
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;
}
namespace fast_number_theory_transform{
const int maxbit=22;
i64 mod_root[maxbit+1]; // mod_root[i]**(2**i) == 1
i64 mod_iroot[maxbit+1]; // mod_iroot[i]*mod_root[i] == 1
__attribute__((constructor))
inline void init_mod_root(){
mod_root[maxbit]=fsp(gen,mod>>(maxbit+1));
mod_iroot[maxbit]=fsp(mod_root[maxbit],mod-2);
for(int i=maxbit;i-->0;)
mod_root[i]=mod_root[i+1]*mod_root[i+1]%mod,
mod_iroot[i]=mod_iroot[i+1]*mod_iroot[i+1]%mod;
}
// butterfly transform
// int rev[1<<24];
template<class T>
inline void butterfly(T* p,int bit) {
for(unsigned 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(unsigned l=1u<<(bit-1);(j^=l)<l;l>>=1);
}
}
inline void ntt(int* a,int bit,bool f=0){
for(int k=bit;k-->0;){
i64 pw=1;
for(int j=0;j<(1<<k)-1;j++,pw=pw*mod_root[k]%mod){
for(int i=j;i<(1<<bit);i+=1<<(k+1)){
int x=a[i],&y=a[i^(1<<k)];
(a[i]+=y)<mod?0:a[i]-=mod;
y=pw*(x+mod-y)%mod;
}
}
for(int i=(1<<k)-1;i<(1<<bit);i+=1<<(k+1)){
int x=a[i],&y=a[i^(1<<k)];
(a[i]+=y)<mod?0:a[i]-=mod;
y=pw*(x+mod-y)%mod;
}
}if(f)butterfly(a,bit);
}
inline void intt(int* a,int bit,bool f=0){
if(f)butterfly(a,bit);
for(int k=0;k<bit;k++){
i64 pw=1;
for(int j=0;j<(1<<k)-1;j++,pw=pw*mod_iroot[k]%mod){
for(int i=j;i<(1<<bit);i+=1<<(k+1)){
int x=a[i],&y=(a[i^(1<<k)]=a[i^(1<<k)]*pw%mod);
(a[i]+=y)<mod?0:a[i]-=mod;
(y=x-y)<0?y+=mod:0;
}
}
for(int i=(1<<k)-1;i<(1<<bit);i+=1<<(k+1)){
int x=a[i],&y=(a[i^(1<<k)]=a[i^(1<<k)]*pw%mod);
(a[i]+=y)<mod?0:a[i]-=mod;
(y=x-y)<0?y+=mod:0;
}
}
i64 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::ntt;
using math::intt;
int n,m,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];
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++)cout<<a[i]<<' ';
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Subtask #1 Testcase #1 | 40.42 us | 68 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #2 | 72.527 ms | 3 MB + 496 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #3 | 32.258 ms | 1 MB + 356 KB | Accepted | Score: 100 | 显示更多 |
| Subtask #1 Testcase #4 | 32.314 ms | 1 MB + 344 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #5 | 41.8 us | 68 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #6 | 40.84 us | 68 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #7 | 40.2 us | 68 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #8 | 68.142 ms | 3 MB + 228 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #9 | 68.071 ms | 3 MB + 228 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #10 | 63.802 ms | 2 MB + 984 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #11 | 72.48 ms | 3 MB + 576 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #12 | 67.291 ms | 2 MB + 456 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #13 | 39.31 us | 68 KB | Accepted | Score: 0 | 显示更多 |