考虑传统的拉格朗日插值法插多项式是的
即构造函数
化一下
考虑如何求出
设
就相当于除以了
那就变成了
但是这个分子分母就都是0了,没法直接求
根据洛必达法则:
若
有
同时取导得到
接下来考虑对整个式子分治
设表示分治得到的答案
先分治求出,多点求值把求出来再分治一波就完了
复杂度
#include<bits/stdc++.h>
using namespace std;
const int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ob==ib)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ob==ib)?EOF:*ib++;
}
#define gc getchar
inline int read(){
char ch=gc();
int res=0,f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
#define ll long long
#define re register
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define cs const
const int mod=998244353,G=3;
inline int add(int a,int b){return a+b>=mod?a+b-mod:a+b;}
inline void Add(int &a,int b){a=add(a,b);}
inline int dec(int a,int b){return a>=b?a-b:a-b+mod;}
inline void Dec(int &a,int b){a=dec(a,b);}
inline int mul(int a,int b){return 1ll*a*b>=mod?1ll*a*b%mod:a*b;}
inline void Mul(int &a,int b){a=mul(a,b);}
inline int ksm(int a,int b,int res=1){for(;b;b>>=1,a=mul(a,a))(b&1)?(res=mul(res,a)):0;return res;}
inline void chemx(int &a,int b){a<b?a=b:0;}
inline void chemn(int &a,int b){a>b?a=b:0;}
cs int N=(1<<17)+1,C=20;
#define poly vector<int>
#define bg begin
poly w[C+1];
int rev[N<<2];
inline void init_rev(int lim){
for(int i=0;i<lim;i++)rev[i]=(rev[i>>1]>>1)|((i&1)*(lim>>1));
}
inline void init_w(){
for(int i=1;i<=C;i++)w[i].resize((1<<(i-1)));
int wn=ksm(G,(mod-1)/(1<<C));
w[C][0]=1;
for(int i=1;i<(1<<(C-1));i++)
w[C][i]=mul(w[C][i-1],wn);
for(int i=C-1;i;i--)
for(int j=0;j<(1<<(i-1));j++)
w[i][j]=w[i+1][j<<1];
}
inline void ntt(poly &f,int lim,int kd){
for(int i=0;i<lim;i++)if(i>rev[i])swap(f[i],f[rev[i]]);
for(int mid=1,l=1;mid<lim;mid<<=1,l++)
for(int i=0,a0,a1;i<lim;i+=(mid<<1))
for(int j=0;j<mid;j++){
a0=f[i+j],a1=mul(f[i+j+mid],w[l][j]);
f[i+j]=add(a0,a1),f[i+j+mid]=dec(a0,a1);
}
if(kd==-1){
reverse(f.begin()+1,f.begin()+lim);
for(int i=0,inv=ksm(lim,mod-2);i<lim;i++)Mul(f[i],inv);
}
}
inline int F(cs poly a,int x){
int p=1,res=0;
for(int i=0;i<a.size();i++,Mul(p,x))Add(res,mul(a[i],p));
return res;
}
inline poly operator +(cs poly &a,cs poly &b){
poly c(max(a.size(),b.size()),0);
for(int i=0;i<c.size();i++)c[i]=add(a[i],b[i]);
return c;
}
inline poly operator -(cs poly &a,cs poly &b){
poly c(max(a.size(),b.size()),0);
for(int i=0;i<c.size();i++)c[i]=dec(a[i],b[i]);
return c;
}
inline poly operator *(poly a,poly b){
int deg=a.size()+b.size()-1,lim=1;
if(deg<=128){
poly c(deg,0);
for(int i=0;i<a.size();i++)
for(int j=0;j<b.size();j++)
Add(c[i+j],mul(a[i],b[j]));
return c;
}
while(lim<deg)lim<<=1;
init_rev(lim);
a.resize(lim),ntt(a,lim,1);
b.resize(lim),ntt(b,lim,1);
for(int i=0;i<lim;i++)Mul(a[i],b[i]);
ntt(a,lim,-1),a.resize(deg);
return a;
}
inline poly Inv(poly a,int deg){
poly b,c(1,ksm(a[0],mod-2));
for(int lim=4;lim<(deg<<2);lim<<=1){
b=a,b.resize(lim>>1);
init_rev(lim);
b.resize(lim),ntt(b,lim,1);
c.resize(lim),ntt(c,lim,1);
for(int i=0;i<lim;i++)Mul(c[i],dec(2,mul(b[i],c[i])));
ntt(c,lim,-1),c.resize(lim>>1);
}c.resize(deg);return c;
}
inline poly operator /(poly a,poly b){
int lim=1,deg=a.size()-b.size()+1;
reverse(a.bg(),a.end());
reverse(b.bg(),b.end());
while(lim<deg)lim<<=1;
b=Inv(b,lim),b.resize(deg);
a=a*b,a.resize(deg);
reverse(a.bg(),a.end());
return a;
}
inline poly operator %(poly a,poly b){
poly c=a-(a/b)*b;
c.resize(b.size()-1);
return c;
}
inline poly deriv(poly a){
for(int i=0;i<a.size()-1;i++)a[i]=mul(a[i+1],i+1);
a.pop_back();return a;
}
#define lc (u<<1)
#define rc ((u<<1)|1)
#define mid ((l+r)>>1)
poly f[N<<2];
int n,x[N],y[N],g[N];
inline void build(int u,int l,int r){
if(l==r){f[u].pb(mod-x[l]),f[u].pb(1);return;}
build(lc,l,mid),build(rc,mid+1,r);
f[u]=f[lc]*f[rc];
}
inline void calc(int u,int l,int r,poly res){
if(l==r){
g[l]=mul(ksm(F(res,x[l]),mod-2),y[l]);
return;
}
calc(lc,l,mid,res%f[lc]),calc(rc,mid+1,r,res%f[rc]);
}
inline poly getans(int u,int l,int r){
if(l==r)return poly(1,g[l]);
poly ansl=getans(lc,l,mid),ansr=getans(rc,mid+1,r);
return ansl*f[rc]+ansr*f[lc];
}
int main(){
n=read();
init_w();
for(int i=1;i<=n;i++)x[i]=read(),y[i]=read();
build(1,1,n);
calc(1,1,n,deriv(f[1]));
poly ans=getans(1,1,n);
for(int i=0;i<n;i++)cout<<ans[i]<<" ";
}