QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#114029 | #6349. Is This FFT? | Crysfly | TL | 1ms | 36292kb | C++17 | 6.6kb | 2023-06-20 15:54:09 | 2023-06-20 15:54:11 |
Judging History
answer
// what is matter? never mind.
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
int mod;
typedef unsigned long long ull;
namespace FM{
typedef __uint128_t L;
struct FastMod{
ull b,m;
FastMod(ull b):b(b),m(ull((L(1)<<64)/b)){}
ull reduce(ull a){ull q=(ull)((L(m)*a)>>64),r=a-q*b;return r>=b?r-b:r;}
};
FastMod F(2);
}
void initmod(){mod=read(),FM::F=FM::FastMod(mod);}
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=FM::F.reduce(1ull*x*o.x),*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,int b){return a.x==b;}
friend bool operator !=(modint a,int b){return a.x!=b;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define poly vector<modint>
modint G,Ginv;
inline poly one(){poly a;a.push_back(1);return a;}
vector<int>rev;
vector<modint>rts;
inline int ext(int n){
int k=0;
while((1<<k)<n)++k;return k;
}
inline void init(int k){
int n=1<<k;
if(rev.size()==n)return;
rev.resize(n);
For(i,0,n-1)rev[i]=(rev[i>>1]>>1)|((i&1)<<(k-1));
if(rts.size()>=n)return;
int lst=max(1,(int)rts.size()); rts.resize(n);
for(int mid=lst;mid<n;mid<<=1){
modint wn=G^((mod-1)/(mid<<1));
rts[mid]=1;
For(i,1,mid-1)rts[i+mid]=rts[i+mid-1]*wn;
}
}
void ntt(poly&a,int k,int typ)
{
int n=1<<k;
if(typ<0) reverse(a.begin()+1,a.end());
For(i,0,n-1)if(i<rev[i])swap(a[i],a[rev[i]]);
for(int mid=1;mid<n;mid<<=1)
for(int r=mid<<1,j=0;j<n;j+=r)
for(int k=0;k<mid;++k){
modint x=a[j+k],y=rts[mid+k]*a[j+k+mid];
a[j+k]=x+y,a[j+k+mid]=x-y;
}
if(typ<0){
modint inv=modint(1)/n;
For(i,0,n-1)a[i]*=inv;
}
}
poly operator +(poly a,poly b){
int n=max(a.size(),b.size());a.resize(n),b.resize(n);
For(i,0,n-1)a[i]+=b[i];return a;
}
poly operator -(poly a,poly b){
int n=max(a.size(),b.size());a.resize(n),b.resize(n);
For(i,0,n-1)a[i]-=b[i];return a;
}
poly operator *(poly a,modint b){
int n=a.size();
For(i,0,n-1)a[i]*=b;return a;
}
poly operator *(poly a,poly b)
{
if((int)a.size()<=64 && (int)b.size()<=64){
poly c(a.size()+b.size()-1,0);
for(int i=0;i<a.size();++i)
for(int j=0;j<b.size();++j)
c[i+j]+=a[i]*b[j];
return c;
}
int n=(int)a.size()+(int)b.size()-1,k=ext(n);
a.resize(1<<k),b.resize(1<<k),init(k);
ntt(a,k,1),ntt(b,k,1);
For(i,0,(1<<k)-1)a[i]*=b[i];
ntt(a,k,-1),a.resize(n);return a;
}
poly Tmp;
poly pmul(poly a,poly b,int n,bool ok=0)
{
int k=ext(n); init(k);
a.resize(1<<k),ntt(a,k,1);
if(!ok) b.resize(1<<k),ntt(b,k,1),Tmp=b;
For(i,0,(1<<k)-1)a[i]*=Tmp[i];
ntt(a,k,-1),a.resize(n);
return a;
}
poly inv(poly a,int n)
{
a.resize(n);
if(n==1){
poly f(1,1/a[0]);
return f;
}
poly f0=inv(a,(n+1)>>1),f=f0;
poly now=pmul(a,f0,n,0);
for(int i=0;i<f0.size();++i)now[i]=0;
now=pmul(now,poly(0),n,1);
f.resize(n);
for(int i=f0.size();i<n;++i)f[i]=-now[i];
return f;
}
poly inv(poly a){
return inv(a,a.size());
}
poly deriv(poly a){
int n=(int)a.size()-1;
For(i,0,n-1)a[i]=a[i+1]*(i+1);
a.resize(n);return a;
}
poly inter(poly a){
int n=a.size()+1;a.resize(n);
Rep(i,n-1,1)a[i]=a[i-1]/i;
a[0]=0;return a;
}
poly ln(poly a){
int n=a.size();
a=inter(deriv(a)*inv(a));
a.resize(n);return a;
}
poly exp(poly a,int k){
int n=1<<k;a.resize(n);
if(n==1)return one();
poly f0=exp(a,k-1);f0.resize(n);
return f0*(one()+a-ln(f0));
}
poly exp(poly a){
int n=a.size();
a=exp(a,ext(n));a.resize(n);return a;
}
poly div(poly a,poly b){
int n=a.size(),m=b.size(),k=ext(n-m+1);
reverse(a.begin(),a.end()),reverse(b.begin(),b.end());
a.resize(n-m+1),b.resize(n-m+1);
a=a*inv(b),a.resize(n-m+1),reverse(a.begin(),a.end()); return a;
}
poly modulo(poly a,poly b){
if(b.size()>a.size())return a;
int n=b.size()-1;
a=a-div(a,b)*b;a.resize(n);return a;
}
#define maxn 500005
#define inf 0x3f3f3f3f
namespace qwq{
int divs[233],cnt;
int getphi(int n){
int res=n;
For(i,2,n/i)
if(n%i==0){
res/=i,res*=(i-1);
while(n%i==0)n/=i;
}
if(n>1)res/=n,res*=(n-1);
return res;
}
void getfac(int n){
For(i,2,n/i)
if(n%i==0){
while(n%i==0)
n/=i,divs[++cnt]=i;
}
if(n>1)divs[++cnt]=n;
}
bool chk(modint x){
int res=mod-1;
For(i,1,cnt)
if((x^(res/divs[i])).x==1) return 0;
return 1;
}
int GetG(){
getfac(mod-1);
For(i,2,mod-1)if(chk(i))return i;
}
}
void init_mod(){
initmod();
G=qwq::GetG(),Ginv=1/G;
}
int n,up[256];
modint f[256][256*256/2];
modint F(int n,int m){
return C(n+m,m);
}
signed main()
{
n=read(),init_mod(),initC(n*n+5);
f[1][0]=1;
For(i,1,n)up[i]=i*(i-1)/2;
For(i,2,n){
// f[j][x] -> f[j][x]*ifac[x]
For(j,1,i-1){
int k=i-j;
For(x,0,up[j])
For(y,0,up[k])
f[i][x+y+j*(i-j)-1]+=f[j][x]*f[k][y]*
fac[up[j]-x+up[k]-y]*fac[x+y+j*(i-j)-1]
*ifac[up[j]-x]*ifac[up[k]-y]*ifac[x]*ifac[y];
}
Rep(j,up[i],1) f[i][j-1]+=f[i][j];
modint res=f[i][0];
res*=ifac[up[i]]*fac[i]*((mod+1)/2);
cout<<res.x<<"\n";
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 36292kb
input:
10 998244353
output:
1 1 532396989 328786831 443364983 567813846 34567523 466373946 474334062
result:
ok 9 numbers
Test #2:
score: -100
Time Limit Exceeded
input:
250 998244353