正文
增加 290 行删除 224 行
27 行未改动2829303132333435365 行未改动424344454647484950515213 行未改动666768697071727374757677787980818283848586878889909192939495969798991001011021031043 行未改动10810911011111211311411511611711811912012112212312412512612712812913017 行未改动14814915015115215315415515615711 行未改动16917017117217317417517617717817911 行未改动19119219319419519619719819920020129 行未改动23123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930067 行未改动36836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553627 行未改动ll q;cin>>q;ans.a.push_back(q);}while(!ans.a.empty()&&!ans.a.back())ans.a.pop_back();return ans;}void ask(poly x){5 行未改动{cout<<x.a[i]<<" ";}}ll rev[MAXN];ll wj[MAXN];void NTT(ll *x,ll y){for(register int i=0;i<y;i++){if(i<rev[i])swap(x[i],x[rev[i]]);13 行未改动}}}}ll nta[MAXN],ntb[MAXN];poly operator *(poly x,poly y){poly ans;if(x.a.empty()){return x;}if(y.a.empty()){return y;}ll xl=x.a.size()-1,yl=y.a.size()-1;for(register int i=0;i<x.a.size();i++){nta[i]=x.a[i];}for(register int i=0;i<y.a.size();i++){ntb[i]=y.a[i];}ll t=1;while(t<=xl+yl)t<<=1;for(register int i=xl+1;i<=t;i++){nta[i]=0;}for(register int i=yl+1;i<=t;i++){ntb[i]=0;}for(register int i=1;i<t;i++){rev[i]=(rev[i>>1]>>1)|((i&1)<<__lg(t)-1);}3 行未改动for(int i=1;i<tttt;i++){wj[i]=wj[i-1]*tt%MOD;}NTT(nta,t);NTT(ntb,t);tt=power(t,MOD-2);for(register int i=0;i<t;i++)nta[i]=nta[i]*ntb[i]%MOD*tt%MOD;tt=power(332748118,(MOD-1)/t);for(int i=1;i<tttt;i++){wj[i]=wj[i-1]*tt%MOD;}NTT(nta,t);for(register int i=0;i<=xl+yl;i++){ans.a.push_back(nta[i]);}return ans;}void operator *=(poly &x,poly y){x=x*y;}void swap(poly &x,poly &y){17 行未改动poly operator -(poly x,poly y){ll xl=x.a.size();ll yl=y.a.size();while(xl<yl)x.a.push_back(0),xl++;for(ll i=0;i<xl;i++){x.a[i]-=y.a[i];}while(!x.a.empty()&&!x.a.back())x.a.pop_back();11 行未改动}void operator *=(poly &x,ll y){x=x*y;}poly operator /(poly x,ll y){for(register int i=0;i<x.a.size();i++){x.a[i]/=y;}while(!x.a.empty()&&!x.a.back())x.a.pop_back();return x;}11 行未改动}void operator %=(poly &x,ll y){x=x%y;}poly mod(poly x,ll y){while(x.a.size()>y)x.a.pop_back();return x;}poly operator <<(poly x,ll y){ll t=x.a.size()-1;for(int i=1;i<=y;i++)29 行未改动}return x;}void operator >>=(poly &x,ll y){x=x>>y;}poly inv(poly x,ll y){poly ans;if(y==1){ans.a.push_back(power(x.a[0],MOD-2));return ans;}ll t=1,tt=y+1>>1;while(t<(tt<<1))t<<=1;ans=inv(mod(x,t),tt);t=1;while(t<(y<<1))t<<=1;return (ans*2-mod(mod(ans*ans,t)*x,t))%MOD;}```FFT```cppll power(ll x,ll y){ll ans=1;while(y){if(y&1){ans*=x;ans%=MOD;}x*=x;x%=MOD;y>>=1;}return ans;}struct poly{vector<ll>a;};poly get(ll x){poly ans;for(ll i=0;i<=x;i++){ll q;cin>>q;ans.a.push_back(q);}while(!ans.a.empty()&&!ans.a.back())ans.a.pop_back();return ans;}void ask(poly x){if(x.a.empty()){return ;}for(ll i=0;i<x.a.size();i++){cout<<x.a[i]<<" ";}}const double PI=acos(-1);ll rev[MAXN];complex<double>wj[MAXN];ll lowbit(ll x)67 行未改动}FFT(ffa,t);FFT(ffb,t);for(register int i=0;i<t;i++)ffa[i]=ffa[i]*ffb[i]/(double)t;for(int i=1;i<tttt;i<<=1){wj[i]={cos(PI/tttt*i),-sin(PI/tttt*i)};}for(int i=1;i<tttt;i++){wj[i]=wj[i-lowbit(i)]*wj[lowbit(i)];}FFT(ffa,t);for(register int i=0;i<=xl+yl;i++){ans.a.push_back(ffa[i].real()+0.5);}return ans;}void operator *=(poly &x,poly y){x=x*y;}void swap(poly &x,poly &y){poly ans=x;x=y;y=ans;}poly operator +(poly x,poly y){ll xl=x.a.size();ll yl=y.a.size();if(xl<yl)swap(x,y),swap(xl,yl);for(ll i=0;i<yl;i++){x.a[i]+=y.a[i];}while(!x.a.empty()&&!x.a.back())x.a.pop_back();return x;}void operator +=(poly &x,poly y){x=x+y;}poly operator -(poly x,poly y){ll xl=x.a.size();ll yl=y.a.size();while(xl<yl)x.a.push_back(0),xl++;for(ll i=0;i<xl;i++){x.a[i]-=y.a[i];}while(!x.a.empty()&&!x.a.back())x.a.pop_back();return x;}void operator -=(poly &x,poly y){x=x-y;}poly operator *(poly x,ll y){for(register int i=0;i<x.a.size();i++){x.a[i]*=y;}while(!x.a.empty()&&!x.a.back())x.a.pop_back();return x;}void operator *=(poly &x,ll y){x=x*y;}poly operator /(poly x,ll y){for(register int i=0;i<x.a.size();i++){x.a[i]/=y;}while(!x.a.empty()&&!x.a.back())x.a.pop_back();return x;}void operator /=(poly &x,ll y){x=x/y;}poly operator %(poly x,ll y){for(register int i=0;i<x.a.size();i++){x.a[i]%=y;x.a[i]+=y;x.a[i]%=y;}while(!x.a.empty()&&!x.a.back())x.a.pop_back();return x;}void operator %=(poly &x,ll y){x=x%y;}poly mod(poly x,ll y){while(x.a.size()>y)x.a.pop_back();return x;}poly mtt(poly x,poly y){poly x0=x/32768,x1=x%32768;poly y0=y/32768,y1=y%32768;return (x0*y0%MOD*1073741824%MOD+(x0*y1+x1*y0)%MOD*32768%MOD+x1*y1)%MOD;}poly operator <<(poly x,ll y){ll t=x.a.size()-1;for(int i=1;i<=y;i++){x.a.push_back(0);}for(int i=t+y;i>=y;i--){x.a[i]=x.a[i-y];}for(int i=y-1;i>=0;i--){x.a[i]=0;}return x;}void operator <<=(poly &x,ll y){x=x<<y;}poly operator >>(poly x,ll y){ll t=x.a.size()-1;if(t<y){poly ans;return ans;}for(int i=0;i<=t-y;i++){x.a[i]=x.a[i+y];}for(int i=1;i<=y;i++){x.a.pop_back();}return x;}void operator >>=(poly &x,ll y){x=x>>y;}poly inv(poly x,ll y){poly ans;if(y==1){ans.a.push_back(power(x.a[0],MOD-2));return ans;}ll t=1,tt=y+1>>1;while(t<(tt<<1))t<<=1;ans=inv(mod(x,t),tt);t=1;while(t<(y<<1))t<<=1;return (ans*2-mod(mtt(mod(mtt(ans,ans),t),x),t))%MOD;}poly reverse(poly x){ll xl=x.a.size()-1;for(int i=0;(i<<1)<=xl;i++){swap(x.a[i],x.a[xl-i]);}return x;}poly operator /(poly x,poly y){ll xl=x.a.size()-1;ll yl=y.a.size()-1;x=reverse(x);y=reverse(y);return reverse(mod(mtt(x,mod(inv(y,xl-yl+1),xl-yl+1)),xl-yl+1));}poly operator %(poly x,poly y){return (x-mtt(x/y,y))%MOD;}```27 行未改动28293031323334355 行未改动414243444546474849505113 行未改动65666768697071727374757677787980818283848586873 行未改动91929394959697989910010110210310410510610710810911017 行未改动12812913013113213313413513613711 行未改动14915015115215315415515615715815916011 行未改动17217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932029 行未改动35035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151267 行未改动58058158258358458558658758858959059159259359459559659759859960060160227 行未改动ll q;cin>>q;ans.a.push_back(q);}return ans;}void ask(poly x){5 行未改动{cout<<x.a[i]<<" ";}}ll rev[MAXN<<2];ll wj[MAXN<<2];void NTT(vector<ll>&x,ll y){for(register int i=0;i<y;i++){if(i<rev[i])swap(x[i],x[rev[i]]);13 行未改动}}}}poly operator *(poly x,poly y){if(x.a.empty()){return x;}if(y.a.empty()){return y;}ll xl=x.a.size()-1,yl=y.a.size()-1;ll t=1;while(t<=xl+yl)t<<=1;x.a.resize(t);y.a.resize(t);for(register int i=1;i<t;i++){rev[i]=(rev[i>>1]>>1)|((i&1)<<__lg(t)-1);}3 行未改动for(int i=1;i<tttt;i++){wj[i]=wj[i-1]*tt%MOD;}NTT(x.a,t);NTT(y.a,t);tt=power(t,MOD-2);for(register int i=0;i<t;i++)x.a[i]=x.a[i]*y.a[i]%MOD*tt%MOD;tt=power(332748118,(MOD-1)/t);for(int i=1;i<tttt;i++){wj[i]=wj[i-1]*tt%MOD;}NTT(x.a,t);while(!x.a.empty()&&!x.a.back())x.a.pop_back();return x;}void operator *=(poly &x,poly y){x=x*y;}void swap(poly &x,poly &y){17 行未改动poly operator -(poly x,poly y){ll xl=x.a.size();ll yl=y.a.size();if(xl<yl)x.a.resize(yl),xl=yl;for(ll i=0;i<yl;i++){x.a[i]-=y.a[i];}while(!x.a.empty()&&!x.a.back())x.a.pop_back();11 行未改动}void operator *=(poly &x,ll y){x=x*y;}poly operator /(poly x,ll y){y=power(y,MOD-2);for(register int i=0;i<x.a.size();i++){x.a[i]*=y;}while(!x.a.empty()&&!x.a.back())x.a.pop_back();return x;}11 行未改动}void operator %=(poly &x,ll y){x=x%y;}poly mod(poly x,ll y){if(x.a.size()>y)x.a.resize(y);return x;}poly inv(poly x,ll y){poly ans;if(y==1){ans.a.push_back(power(x.a[0],MOD-2));return ans;}ll tt=y+1>>1;ans=inv(mod(x,tt),tt);ll t=1;while(t<(y<<1))t<<=1;ans.a.resize(t);x.a.resize(t);for(register int i=1;i<t;i++){rev[i]=(rev[i>>1]>>1)|((i&1)<<__lg(t)-1);}ll tttt=t>>1;wj[0]=1;tt=power(3,(MOD-1)/t);for(int i=1;i<tttt;i++){wj[i]=wj[i-1]*tt%MOD;}NTT(x.a,t);NTT(ans.a,t);tt=power(t,MOD-2);for(int i=0;i<t;i++)x.a[i]=(MOD+2-ans.a[i]*x.a[i]%MOD)*ans.a[i]%MOD*tt%MOD;tt=power(332748118,(MOD-1)/t);for(int i=1;i<tttt;i++){wj[i]=wj[i-1]*tt%MOD;}NTT(x.a,t);return mod(x,y);}poly reverse(poly x){ll xl=x.a.size()-1;for(int i=0;(i<<1)<=xl;i++){swap(x.a[i],x.a[xl-i]);}return x;}poly operator /(poly x,poly y){ll xl=x.a.size()-1;ll yl=y.a.size()-1;if(xl<yl){poly ans;return ans;}x=reverse(x);y=reverse(y);return reverse(mod(x*inv(y,xl-yl+1),xl-yl+1));}void operator /=(poly &x,poly y){x=x/y;}poly operator %(poly x,poly y){return (x-x/y*y)%MOD;}void operator %=(poly &x,poly y){x=x%y;}poly diriv(poly x){if(x.a.empty())return x;ll xl=x.a.size()-1;for(int i=0;i<xl;i++){x.a[i]=x.a[i+1]*(i+1)%MOD;}x.a.pop_back();return x;}ll res[MAXN]={0,1},rescnt=2;poly integ(poly x){if(x.a.empty())return x;ll xl=x.a.size()-1;for(;rescnt<=xl;rescnt++){res[rescnt]=(MOD-MOD/rescnt)*res[MOD%rescnt]%MOD;}for(int i=xl;i>0;i--){x.a[i]=x.a[i-1]*res[i]%MOD;}x.a[0]=0;return x;}poly ln(poly x,ll y){return integ(mod(diriv(x)*inv(x,y),y));}poly exp(poly x,ll y){poly ans;if(y==1){ans.a.push_back(1);return ans;}ll tt=y+1>>1;ans=exp(mod(x,tt),tt);ll t=1;while(t<(y<<1))t<<=1;if(x.a.empty())x.a.push_back(0);x.a[0]++;return mod(ans*((x-ln(ans,y))%MOD),y);}mt19937 rnd(time(0));ll rcsy(ll x){x%=MOD;if(!x)return 0;if(power(x,(MOD-1)/2)==MOD-1)return -1;ll t=rnd()%MOD;ll ttt=(t*t%MOD-x+MOD)%MOD;while(power(ttt,(MOD-1)/2)!=MOD-1){t=rnd()%MOD;ttt=(t*t%MOD-x+MOD)%MOD;}pair<ll,ll> ans={1,0},tt={t,1};t=(MOD+1)/2;while(t){if(t&1){ans={(ans.first*tt.first+ans.second*tt.second%MOD*ttt)%MOD,(ans.first*tt.second+ans.second*tt.first)%MOD};}tt={(tt.first*tt.first+tt.second*tt.second%MOD*ttt)%MOD,(tt.first*tt.second+tt.second*tt.first)%MOD};t>>=1;}return ans.first;}poly operator <<(poly x,ll y){ll t=x.a.size()-1;for(int i=1;i<=y;i++)29 行未改动}return x;}void operator >>=(poly &x,ll y){x=x>>y;}poly sqrt(poly x,ll y){ll tttt=0;for(int i=0;i<x.a.size();i++,tttt++){if(x.a[i])break;}x>>=tttt;tttt>>=1;ll t=x.a[0];x=exp(ln(x/t%MOD,y)/2,y);t=rcsy(t);poly tt=x*t%MOD;poly ttt=x*(MOD-t)%MOD;for(int i=0;i<y;i++){if(tt.a[i]<ttt.a[i]){return tt<<tttt;}if(tt.a[i]>ttt.a[i]){return ttt<<tttt;}}return tt;}poly pow(poly x,ll y,ll z){ll t=0;for(int i=0;i<x.a.size();i++,t++){if(x.a[i])break;}if(t*z>=y||t>=x.a.size()){poly ans;return ans;}x>>=t;return mod((exp(ln(x/x.a[0]%MOD,y)*z%MOD,y)*power(x.a[0],z%998244352)%MOD)<<(t*z),y);}poly mult(poly x,poly y){ll xl=x.a.size();ll yl=y.a.size();y=reverse(y);y=x*y;for(int i=0;i<xl;i++)x.a[i]=y.a[i+yl-1];return x;}poly ddb[MAXN<<2];ll dda[MAXN],ddc[MAXN];void ddinit(ll x,ll l,ll r){if(l==r){ddb[x].a.push_back(1);ddb[x].a.push_back(MOD-dda[l]);return ;}ll mid=l+r>>1;ddinit(x<<1,l,mid);ddinit(x<<1|1,mid+1,r);ddb[x]=ddb[x<<1]*ddb[x<<1|1];}void ddqzdg(ll x,ll l,ll r,poly y){if(l==r){ddc[l]=y.a[0];return ;}ll mid=l+r>>1;ddqzdg(x<<1,l,mid,mod(mult(y,ddb[x<<1|1]),mid-l+1));ddqzdg(x<<1|1,mid+1,r,mod(mult(y,ddb[x<<1]),r-mid));}void ddqz(poly x,ll n){ll t=max((ll)x.a.size(),n);ddinit(1,1,t);x.a.resize(t+1);ddqzdg(1,1,t,mult(x,inv(ddb[1],t+1)));}poly ksc[MAXN<<2];ll ksa[MAXN],ksb[MAXN];void ksinit(ll x,ll l,ll r){if(l==r){ksc[x].a.push_back(MOD-ksa[l]);ksc[x].a.push_back(1);return ;}ll mid=l+r>>1;ksinit(x<<1,l,mid);ksinit(x<<1|1,mid+1,r);ksc[x]=ksc[x<<1]*ksc[x<<1|1];}poly ksczdg(ll x,ll l,ll r){if(l==r){poly ans;ans.a.push_back(ksb[l]);return ans;}ll mid=l+r>>1;return (ksczdg(x<<1,l,mid)*ksc[x<<1|1]+ksczdg(x<<1|1,mid+1,r)*ksc[x<<1])%MOD;}poly kscz(ll n){ksinit(1,1,n);for(int i=1;i<=n;i++){dda[i]=ksa[i];}ddqz(diriv(ksc[1]),n);for(int i=1;i<=n;i++){ksb[i]*=power(ddc[i],MOD-2);}return ksczdg(1,1,n);}poly sin(poly x,ll y){return (exp(x*911660635%MOD,y)-exp(x*86583718%MOD,y))*43291859%MOD;}poly cos(poly x,ll y){return (exp(x*911660635%MOD,y)+exp(x*86583718%MOD,y))*499122177%MOD;}poly tan(poly x,ll y){return mod(sin(x,y)*inv(cos(x,y),y),y);}poly arcsin(poly x,ll y){poly ans;ans.a.push_back(1);return integ(mod(diriv(x)*inv(sqrt((ans-mod(x*x,y))%MOD,y),y),y));}poly arccos(poly x,ll y){return arcsin(x,y)*998244352%MOD;}poly arctan(poly x,ll y){poly ans=mod(x*x,y);if(!ans.a.empty())ans.a[0]=(ans.a[0]+1)%MOD;return integ(mod(diriv(x)*inv(ans,y),y));}```FFT```cppconst double PI=acos(-1);ll rev[MAXN];complex<double>wj[MAXN];ll lowbit(ll x)67 行未改动}FFT(ffa,t);FFT(ffb,t);for(register int i=0;i<t;i++)ffa[i]=ffa[i]*ffb[i]/(double)t;for(int i=1;i<tttt;i++){wj[i].imag(-wj[i].imag());}FFT(ffa,t);for(register int i=0;i<=xl+yl;i++){ans.a.push_back(ffa[i].real()+0.5);}return ans;}void operator *=(poly &x,poly y){x=x*y;}poly mtt(poly x,poly y){poly x0=x/32768,x1=x%32768;poly y0=y/32768,y1=y%32768;return (x0*y0%MOD*1073741824%MOD+(x0*y1+x1*y0)%MOD*32768%MOD+x1*y1)%MOD;}```