快速插值 O ( N l o g 2 N ) O(N log^2 N) O(Nlog2N)板子。
话说这代码居然比 O ( N l o g 3 N ) O(N log^3 N) O(Nlog3N)更短更好写。。。
实测本题 O ( N l o g 3 N ) O(N log^3 N) O(Nlog3N)的时间是 O ( N l o g 2 N ) O(N log^2 N) O(Nlog2N)的5~6倍左右。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define SF scanf
#define PF printf
#define MAXN 3000010
#define MOD 998244353
using namespace std;
void Read(int &x){
char c;
while(c=getchar(),c!=EOF&&(c<'0'||c>'9'));
x=c-'0';
while(c=getchar(),c!=EOF&&c>='0'&&c<='9')
x=x*10+c-'0';
}
char p1[20];
void Print(int x){
if(x==0){
putchar('0');
}
int tot=0;
while(x){
p1[tot++]=x%10+'0';
x/=10;
}
for(int i=tot-1;i>=0;i--)
putchar(p1[i]);
putchar(' ');
}
const int G=3;
int n,m,b[MAXN],WN[30],INVW[30];
int buf[MAXN*4];
int *bgn[MAXN],*ncnt=buf;
int fsp(int x,int y){
int res=1;
while(y){
if(y&1)
res=1ll*res*x%MOD;
x=1ll*x*x%MOD;
y>>=1;
}
return res;
}
void ntt(int A[