退役萌新求助QwQ

P5245 【模板】多项式快速幂

代码QAQ ```cpp #include<bits/stdc++.h> #define Ome 3 #define int long long using namespace std; constexpr int maxn=300010,mod=998244353; struct IO_Tp { static const int _I_Buffer_Size = 15 << 20; char _I_Buffer[_I_Buffer_Size], *_I_pos = _I_Buffer; static const int _O_Buffer_Size = 15 << 20; char _O_Buffer[_O_Buffer_Size], *_O_pos = _O_Buffer; IO_Tp() {fread(_I_Buffer, 1, _I_Buffer_Size, stdin);} ~IO_Tp() {fwrite(_O_Buffer, 1, _O_pos - _O_Buffer, stdout);} IO_Tp &operator>>(int &res) { while (!isdigit(*_I_pos)) ++_I_pos; res = *_I_pos++ & 15; while (isdigit(*_I_pos)) (res *= 10) += *_I_pos++ & 15,res-=(res>=mod?mod:0); return *this; } char getop() { while (!isalpha(*_I_pos)) _I_pos++; return *_I_pos++; } IO_Tp &operator<<(int n) { static char _buf[60]; char *_pos(_buf); do *_pos++ = '0' + n % 10; while (n /= 10); while (_pos != _buf) *_O_pos++ = *--_pos; return *this; } IO_Tp &operator<<(char ch) { *_O_pos++ = ch; return *this; } IO_Tp &operator<<(const char *s) { while (*s) *_O_pos++ = *s++; return *this; } } IO; int n,k,N,C,len,rev[maxn],w[maxn],f[maxn],rt[maxn],Inv[maxn],ln[maxn],Exp[maxn]; int pow_mod(int v,int p){ int tmp=1; while(p){ if(p&1)tmp=1LL*tmp*v%mod; v=1LL*v*v%mod;p>>=1; } return tmp; } void FFT(int *A,int n,int flag){ for(int i=0;i<n;++i)if(i<rev[i])swap(A[i],A[rev[i]]); for(int k=2;k<=n;k<<=1){ int mk=(k>>1); int wn=pow_mod(Ome,flag==1?(mod-1)/k:(mod-1)-(mod-1)/k); w[0]=1; for(int i=1;i<mk;++i)w[i]=1LL*w[i-1]*wn%mod; for(int i=0;i<n;i+=k){ for(int j=0;j<mk;++j){ int a=i+j,b=i+j+mk; int x=A[a],y=1LL*A[b]*w[j]%mod; A[a]=(x+y)%mod; A[b]=x-y;if(A[b]<0)A[b]+=mod; } } } if(flag==-1){ int c=pow_mod(n,mod-2); for(int i=0;i<n;++i)A[i]=1LL*A[i]*c%mod; } } void Get_inte(int *f,int n){ for(int i=n-1;i>=1;--i)f[i]=1LL*f[i-1]*pow_mod(i,mod-2)%mod; f[0]=0; } void Get_der(int *f,int n){ f[n]=0; for(int i=0;i<n;++i)f[i]=1LL*f[i+1]*(i+1)%mod; } void Get_inv(int n,int *h){ if(n==1){ Inv[0]=pow_mod(h[0],mod-2); return; } Get_inv(n>>1,h); int now=(n<<1); static int tmp[maxn]; for(int i=0;i<n;++i)tmp[i]=h[i]; for(int i=n;i<now;++i)tmp[i]=0; for(len=0;(1<<len)<now;++len); for(int i=0;i<now;++i)rev[i]=rev[i>>1]>>1|((i&1)<<(len-1)); FFT(tmp,now,1);FFT(Inv,now,1); for(int i=0;i<now;++i)Inv[i]=1LL*Inv[i]*(2LL-1LL*tmp[i]*Inv[i]%mod+mod)%mod; FFT(Inv,now,-1); memset(Inv+n,0,sizeof(int)*n); } void Get_root(int n){ if(n==1){ rt[0]=(int)(sqrt(f[0])); return; } Get_root(n>>1); int now=(n<<1); for(int i=0;i<now;++i)Inv[i]=0; Get_inv(n,rt); static int tmp[maxn]; for(int i=0;i<n;++i)tmp[i]=f[i]; for(int i=n;i<now;++i)tmp[i]=0; for(len=0;(1<<len)<now;++len); for(int i=0;i<now;++i)rev[i]=rev[i>>1]>>1|((i&1)<<(len-1)); FFT(tmp,now,1);FFT(Inv,now,1); for(int i=0;i<now;++i)tmp[i]=1LL*tmp[i]*Inv[i]%mod; FFT(tmp,now,-1); for(int i=0;i<n;++i)rt[i]=1LL*C*(rt[i]+tmp[i])%mod; } void Get_ln(int n,int *h){ int now=(n<<1); for(int i=0;i<now;++i)Inv[i]=0; Get_inv(n,h);Get_der(h,n); for(len=0;(1<<len)<now;++len); for(int i=0;i<now;++i)rev[i]=rev[i>>1]>>1|((i&1)<<(len-1)); FFT(h,now,1);FFT(Inv,now,1); for(int i=0;i<now;++i)ln[i]=1LL*h[i]*Inv[i]%mod; FFT(ln,now,-1); memset(ln+n,0,sizeof(int)*n); Get_inte(ln,n); } void Get_Exp(int n){ if(n==1){Exp[0]=1;return;} Get_Exp(n>>1); int now=(n<<1); static int g[maxn]; for(int i=0;i<n;++i)g[i]=Exp[i]; for(int i=n;i<now;++i)g[i]=0; Get_ln(n,g); for(int i=0;i<n;++i)ln[i]=((i==0)-ln[i]+f[i]+mod)%mod; for(len=0;(1<<len)<now;++len); for(int i=0;i<now;++i)rev[i]=rev[i>>1]>>1|((i&1)<<(len-1)); FFT(ln,now,1);FFT(Exp,now,1); for(int i=0;i<now;++i)Exp[i]=1LL*Exp[i]*ln[i]%mod; FFT(Exp,now,-1); memset(Exp+n,0,sizeof(int)*n); } signed main(){ IO>>n>>k,k%=mod,C=((mod+1)>>1);IO<<k<<'\n'; for(int i=0;i<n;++i) IO>>f[i]; for(N=1;N<=n;N<<=1); Get_ln(N,f); for(int i=0;i<n;++i) f[i]=1LL*ln[i]*k%mod; Get_Exp(N); for(int i=0;i<n;++i) IO<<Exp[i]<<' '; return 0; } ```
by rEdWhitE_uMbrElla @ 2019-03-09 23:01:24


io的时候爆longlong了吧
by SSerxhs @ 2019-03-09 23:05:42


@[SSerxhs](/space/show?uid=29826) 哪爆了。。。
by rEdWhitE_uMbrElla @ 2019-03-09 23:07:54


@[SLF_LLL_SPFA](/space/show?uid=119553) 你一个int*10不是爆了吗
by SSerxhs @ 2019-03-09 23:08:16


@[SLF_LLL_SPFA](/space/show?uid=119553) 退役还萌新就假过头了吧qwq
by star_city @ 2019-03-09 23:09:38


@[SSerxhs](/space/show?uid=29826) 不是 ```cpp #define int long long ``` 了吗。。。
by rEdWhitE_uMbrElla @ 2019-03-09 23:10:32


@[SLF_LLL_SPFA](/space/show?uid=119553) ~~那还没事1LL~~
by SSerxhs @ 2019-03-09 23:12:30


@[SSerxhs](/space/show?uid=29826) ~~因为之前的板子是int~~
by rEdWhitE_uMbrElla @ 2019-03-09 23:13:48


@[SLF_LLL_SPFA](/space/show?uid=119553) orz 神仙
by NaCly_Fish @ 2019-03-09 23:15:20


@[NaCly_Fish](/space/show?uid=115864) QAQ别orz萌新啊。。解决问题啊QAQ
by rEdWhitE_uMbrElla @ 2019-03-09 23:17:12


| 下一页