#include<bits/stdc++.h>
using namespace std;
namespace io
{
const int size = (1 << 20) + 1;
char buf[size], *p1 = buf, *p2 = buf;
char buffer[size];
int op1 = -1;
const int op2 = size - 1;
struct FastIO
{
inline char readchar()
{
return p1 != p2 ? *p1++ : p1 == (p2 = (p1 = buf) + fread(buf, 1, size - 1, stdin)) ? EOF
: *p1++;
}
// #ifndef ONLINE_JUDGE
// #define readchar getchar
// #endif
inline char rc()
{
char c=readchar();
while(c<32 || c==127) c=readchar();
return c;
}
inline void flush()
{
fwrite(buffer, 1, op1 + 1, stdout), op1 = -1;
}
inline void writechar(const char &x)
{
if (op1 == op2)
flush();
buffer[++op1] = x;
}
inline int readint()
{
int s = 1, x = 0;
char c = readchar();
while (c <= 32)
{
c = readchar();
}
if (c == '-')
{
s = -1, c = readchar();
}
while ('0' <= c && c <= '9')
{
x = x * 10 + c - '0';
c = readchar();
}
return x * s;
}
inline int readuint()
{
int x = 0;
char c = readchar();
while (c <= 32)
{
c = readchar();
}
while ('0' <= c && c <= '9')
{
x = x * 10 + c - '0';
c = readchar();
}
return x;
}
inline void writeint(int x)
{
if (x < 0)
{
writechar('-'), x = -x;
}
char s[24];
int n = 0;
while (x || !n)
{
s[n++] = '0' + x % 10, x /= 10;
}
while (n--)
{
writechar(s[n]);
}
}
inline void writeuint(unsigned x)
{
char s[24];
int n = 0;
while (x || !n)
{
s[n++] = '0' + x % 10, x /= 10;
}
while (n--)
{
writechar(s[n]);
}
}
inline long long readlonglong()
{
long long x = 0, s = 1;
char c = readchar();
while (c <= 32)
{
c = readchar();
}
if (c == '-')
{
s = -1, c = readchar();
}
while ('0' <= c && c <= '9')
{
x = x * 10 + c - '0';
c = readchar();
}
return x * s;
}
inline unsigned long long readulonglong()
{
unsigned long long x = 0;
char c = readchar();
while (c <= 32)
{
c = readchar();
}
while ('0' <= c && c <= '9')
{
x = x * 10 + c - '0';
c = readchar();
}
return x;
}
inline void writelonglong(long long x)
{
if (x < 0)
{
writechar('-'), x = -x;
}
char s[25];
int n = 0;
while (x || !n)
{
s[n++] = '0' + x % 10, x /= 10;
}
while (n--)
{
writechar(s[n]);
}
}
inline void writeulonglong(unsigned long long x)
{
char s[25];
int n = 0;
while (x || !n)
{
s[n++] = '0' + x % 10, x /= 10;
}
while (n--)
{
writechar(s[n]);
}
}
inline int readstring(char *s)
{
int cnt = 0;
char c = readchar();
while (c <= 32)
{
c = readchar();
}
while (c > 32)
{
*s++ = c, ++cnt;
c = readchar();
}
return *s = 0, cnt;
}
inline void writestring(const char *s)
{
while (*s)
{
writechar(*s++);
}
}
inline double readdouble()
{
int zheng = 0, fuhao = 1;
double xiao = 0, chushu = 10;
char c;
while ((c = readchar()) < '0' || c > '9')
{
if (c == '-')
{
fuhao = -1;
}
}
while (c >= '0' && c <= '9')
{
zheng = zheng * 10 + c - '0';
c = readchar();
}
if (c != '.')
{
return fuhao * zheng;
}
while ((c = readchar()) >= '0' && c <= '9')
{
xiao += (c - '0') / chushu;
chushu *= 10;
}
return fuhao * (zheng + xiao);
}
} io;
#define readc io::io.rc
#define writec io::io.writechar
#define read io::io.readint
#define readu io::io.readuint
#define write io::io.writeint
#define writeu io::io.writeuint
#define readl io::io.readlonglong
#define readlu io::io.readulonglong
#define writel io::io.writelonglong
#define writelu io::io.writeulonglong
#define reads io::io.readstring
#define writes io::io.writestring
#define readd io::io.readdouble
#define flush io::io.flush
} using namespace io;
const int mod=998244353,g=3,gi=(mod+1)/g;
inline int add(const int &a,const int &b) { return a+b<mod?a+b:a+b-mod; }
int qpow(int a,int b)
{
int ans=1;
while(b!=0)
{
if(b%2==1) ans=1ll*ans*a%mod;
a=1ll*a*a%mod,b/=2;
}
return ans;
}
const double pi=acos(-1);
int n,m;
int a[1<<21],b[1<<21];
int id[1<<21];
vector<int> ppow[21];
void ntt(int n,int *a)
{
for(int i=0; i<n; ++i)
{
if(id[i]>i) swap(a[i],a[id[i]]);
}
for(int lg=0; lg<__lg(n); ++lg)
{
int len=(1<<lg);
for(int l=0; l<n; l+=2*len)
{
for(int i=l; i<l+len; ++i)
{
int tmp=1ll*ppow[lg][i-l]*a[i+len]%mod,x=add(a[i],tmp),y=add(a[i],mod-tmp);
a[i]=x,a[i+len]=y;
}
}
}
}
void intt(int n,int *a)
{
ntt(n,a),reverse(a+1,a+n);
int invn=qpow(n,mod-2);
for(int i=0; i<=n-1; ++i) a[i]=1ll*a[i]*invn%mod;
}
signed main()
{
n=read(),m=read(); int lstlen=n+m;
for(int i=0; i<=n; ++i) a[i]=read();
for(int i=0; i<=m; ++i) b[i]=read();
int lg=__lg(max(n,m))+2,n=(1<<lg);
id[0]=0;
for(int i=1; i<=lg; ++i)
{
for(int j=(1<<i-1); j<(1<<i); ++j) id[j]=id[j-(1<<i-1)]+(1<<lg-i);
}
for(int i=0; i<=lg-1; ++i)
{
int len=(1<<i);
int w=qpow(g,(mod-1)/(len*2)),noww=1;
for(int j=0; j<len; ++j) ppow[i].push_back(noww),noww=1ll*noww*w%mod;
}
ntt(n,a),ntt(n,b);
for(int i=0; i<=n-1; ++i) a[i]=1ll*a[i]*b[i]%mod;
intt(n,a);
for(int i=0; i<=lstlen; ++i) write(a[i]),writec(' ');
return flush(),0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Subtask #1 Testcase #1 | 39.86 us | 56 KB | Accepted | Score: 100 | 显示更多 |
Subtask #1 Testcase #2 | 27.606 ms | 7 MB + 360 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #3 | 26.583 ms | 5 MB + 300 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #4 | 26.023 ms | 5 MB + 280 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #5 | 37.53 us | 56 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #6 | 36.91 us | 56 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #7 | 36.34 us | 56 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #8 | 26.836 ms | 7 MB + 24 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #9 | 26.487 ms | 7 MB + 24 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #10 | 26.567 ms | 6 MB + 608 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #11 | 27.142 ms | 7 MB + 440 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #12 | 25.323 ms | 5 MB + 716 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #13 | 36.29 us | 56 KB | Accepted | Score: 0 | 显示更多 |