結果
問題 | No.1068 #いろいろな色 / Red and Blue and more various colors (Hard) |
ユーザー | tko919 |
提出日時 | 2020-05-29 21:55:31 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 7,517 bytes |
コンパイル時間 | 2,271 ms |
コンパイル使用メモリ | 182,120 KB |
実行使用メモリ | 80,588 KB |
最終ジャッジ日時 | 2024-11-06 04:11:45 |
合計ジャッジ時間 | 11,973 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
32,004 KB |
testcase_01 | AC | 38 ms
31,864 KB |
testcase_02 | AC | 38 ms
31,864 KB |
testcase_03 | AC | 53 ms
32,956 KB |
testcase_04 | AC | 48 ms
32,648 KB |
testcase_05 | AC | 50 ms
32,812 KB |
testcase_06 | AC | 47 ms
32,640 KB |
testcase_07 | AC | 46 ms
32,392 KB |
testcase_08 | AC | 48 ms
32,772 KB |
testcase_09 | AC | 50 ms
32,868 KB |
testcase_10 | AC | 43 ms
32,268 KB |
testcase_11 | AC | 45 ms
32,476 KB |
testcase_12 | AC | 43 ms
32,176 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | AC | 473 ms
80,456 KB |
testcase_30 | AC | 469 ms
80,584 KB |
testcase_31 | AC | 38 ms
31,920 KB |
ソースコード
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; //template #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(v) (v).begin(),(v).end() typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12; template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;} template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} //end template<unsigned mod=998244353>struct fp { unsigned v; static unsigned get_mod(){return mod;} unsigned inv() const{ int tmp,a=v,b=mod,x=1,y=0; while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y); if(x<0){x+=mod;} return x; } fp():v(0){} fp(ll x):v(x>=0?x%mod:mod+(x%mod)){} fp operator-()const{return fp(-v);} fp pow(ll t){fp res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;} return res;} fp& operator+=(const fp& x){if((v+=x.v)>=mod)v-=mod; return *this;} fp& operator-=(const fp& x){if((v+=mod-x.v)>=mod)v-=mod; return *this;} fp& operator*=(const fp& x){v=ll(v)*x.v%mod; return *this;} fp& operator/=(const fp& x){v=ll(v)*x.inv()%mod; return *this;} fp operator+(const fp& x)const{return fp(*this)+=x;} fp operator-(const fp& x)const{return fp(*this)-=x;} fp operator*(const fp& x)const{return fp(*this)*=x;} fp operator/(const fp& x)const{return fp(*this)/=x;} bool operator==(const fp& x)const{return v==x.v;} bool operator!=(const fp& x)const{return v!=x.v;} }; using Fp=fp<>; template<typename T>struct factorial { vector<T> Fact,Finv,Inv; factorial(int maxx){ Fact.resize(maxx); Finv.resize(maxx); Inv.resize(maxx); Fact[0]=Fact[1]=Finv[0]=Finv[1]=Inv[1]=1; rep(i,2,maxx){Fact[i]=Fact[i-1]*i;} Finv[maxx-1]=Fact[maxx-1].inv(); for(int i=maxx-1;i>=2;i--){Finv[i-1]=Finv[i]*i; Inv[i]=Finv[i]*Fact[i-1];} } T fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];} T inv(int n){return Inv[n];} T nPr(int n,int r){if(n<0||n<r||r<0)return Fp(0);else return Fact[n]*Finv[n-r];} T nCr(int n,int r){if(n<0||n<r||r<0)return Fp(0);else return Fact[n]*Finv[r]*Finv[n-r];} }; template<typename T,unsigned p>struct NTT{ vector<T> rt,irt; NTT(int lg=21){ const unsigned m=T(-1).v; T prt=p; rt.resize(1<<lg,1); irt.resize(1<<lg,1); for(int w=0;w<lg;w++){ int mask=1<<w; T g=prt.pow(m>>w),ig=g.inv(); for(int i=0;i<mask-1;i++){ rt[mask+i+1]=g*rt[mask+i]; irt[mask+i+1]=ig*irt[mask+i]; } } } void ntt(vector<T>& f,bool inv=0){ int n=f.size(); if(inv){ for(int i=1;i<n;i<<=1)for(int j=0;j<n;j+=i*2)for(int k=0;k<i;k++){ f[i+j+k]*=irt[i*2+k]; T tmp=f[j+k]-f[i+j+k]; f[j+k]+=f[i+j+k]; f[i+j+k]=tmp; } T mul=T(n).inv(); rep(i,0,n)f[i]*=mul; }else{ for(int i=n>>1;i;i>>=1)for(int j=0;j<n;j+=i*2)for(int k=0;k<i;k++){ T tmp=f[j+k]-f[i+j+k]; f[j+k]+=f[i+j+k]; f[i+j+k]=tmp*rt[i*2+k]; } } } vector<T> conv(vector<T> a,vector<T> b,bool same){ if(a.empty() and b.empty())return vector<T>(); int n=a.size()+b.size()-1,m=1; while(m<n)m<<=1; a.resize(m); ntt(a); if(same)rep(i,0,m)a[i]*=a[i]; else{b.resize(m); ntt(b); rep(i,0,m)a[i]*=b[i];} ntt(a,1); a.resize(n); return a; } }; NTT<Fp,3> ntt; inline vector<Fp> multiply(vector<Fp> a,vector<Fp> b,bool same=0){return ntt.conv(a,b,same);}; factorial<Fp> fact(1048576); template<typename T>struct Poly{ vector<T> f; Poly(){} Poly(int _n):f(_n){} Poly(vector<T> _f){f=_f;} T& operator[](const int i){return f[i];} T eval(T x){T res,w=1; for(T v:f)res+=w*v,w*=x; return res;} int size()const{return f.size();} Poly resize(int n){Poly res=*this; res.f.resize(n); return res;} void shrink(){while(!f.empty() and f.back()==0)f.pop_back();} Poly inv()const{ assert(f[0]!=0); int n=f.size(); Poly res(1); res[0]=f[0].inv(); for(int k=1;k<n;k<<=1){ Poly g=res,h=*this; h=h.resize(k*2); res=res.resize(k*2); g=(g.square()*h).resize(k*2); rep(i,k,min(k*2,n))res[i]-=g[i]; } return res; } Poly square(){return Poly(multiply(f,f,1));} Poly operator+(const Poly& g)const{return Poly(*this)+=g;} Poly operator-(const Poly& g)const{return Poly(*this)-=g;} Poly operator*(const Poly& g)const{return Poly(*this)*=g;} Poly operator/(const Poly& g)const{return Poly(*this)/=g;} Poly operator%(const Poly& g)const{return Poly(*this)%=g;} Poly& operator+=(Poly g){ if(g.size()>f.size())f.resize(g.size()); rep(i,0,g.size())f[i]+=g[i]; shrink(); return *this; } Poly& operator-=(Poly g){ if(g.size()>f.size())f.resize(g.size()); rep(i,0,g.size())f[i]-=g[i]; shrink(); return *this; } Poly& operator*=(Poly g){f=multiply(f,g.f); shrink(); return *this;} Poly& operator/=(Poly g){ if(g.size()>f.size())return *this=Poly(); reverse(ALL(f)); reverse(ALL(g.f)); int n=f.size()-g.size()+1; f.resize(n); g.f.resize(n); *this*=g.inv(); f.resize(n); reverse(ALL(f)); shrink(); return *this; } Poly& operator%=(Poly g){*this-=*this/g*g; shrink(); return *this;} Poly diff(){Poly res(f.size()-1); rep(i,0,res.size())res[i]=f[i+1]*(i+1); return res;} Poly inte(){Poly res(f.size()+1); for(int i=res.size()-1;i;i--)res[i]=f[i-1]*fact.inv(i); return res;} Poly log(){ assert(f[0]==1); int n=f.size(); Poly res=diff()*inv(); res=res.inte(); return res.resize(n); } Poly exp(){ assert(f[0]==0); int n=f.size(); Poly res(1),g(1); res[0]=g[0]=1; for(int k=1;k<n;k<<=1){ g=(g+g-g.square()*res).resize(k); Poly q=resize(k).diff(); Poly w=(q+g*(res.diff()-res*q)).resize(2*k-1); res=(res+res*(resize(k*2)-w.inte())).resize(2*k); } return res.resize(n); } Poly shift(int c){ int n=f.size(); Poly res=*this,mul(n); mul[1]=c; mul=mul.exp(); rep(i,0,n)res[i]*=fact.fact(i); reverse(ALL(res.f)); res*=mul; res=res.resize(n); reverse(ALL(res.f)); rep(i,0,n)res[i]*=fact.fact(i,1); return res; } }; template<typename T>struct Multipoint_evaluation{ int n; vector<T> xs; vector<Poly<T>> buf; Multipoint_evaluation(){} Multipoint_evaluation(const vector<T>& _xs):n(_xs.size()),xs(_xs),buf(4*n){pre(0,n,1);} void pre(int l,int r,int k){ if(r-l==1){buf[k].f={xs[l]*-1,1}; return;} int m=(l+r)>>1; pre(l,m,k*2); pre(m,r,k*2+1); buf[k]=buf[k*2]*buf[k*2+1]; } vector<T> run(const Poly<T>& f){ vector<T> res(n); function<void(Poly<T>,int,int,int)> dfs=[&](Poly<T> g,int l,int r,int k){ g%=buf[k]; if(r-l<=128){rep(i,l,r)res[i]=g.eval(xs[i]); return;} int m=(l+r)>>1; dfs(g,l,m,k*2); dfs(g,m,r,k*2+1); }; dfs(f,0,n,1); return res; } Poly<T> build(const vector<T>& ys){ Poly<T> w=buf[1].diff(); auto vs=run(w); function<Poly<T>(int,int,int)> dfs=[&](int l,int r,int k){ if(r-l==1){Poly<T> res(1); res[0]=ys[l]/vs[l]; return res;} int m=(l+r)>>1; return buf[k*2+1]*dfs(l,m,k*2)+buf[k*2]*dfs(m,r,k*2+1); }; Poly<T> res=dfs(0,n,1); res.resize(n); return res; } }; int main(){ int n,q; cin>>n>>q; vector<Fp> a(n); rep(i,0,n){ int x; cin>>x; a[i]=-x+1; } Multipoint_evaluation<Fp> mul(a); auto res=mul.buf[1]; rep(_,0,q){ int x; cin>>x; cout<<res[x].v<<endl; } return 0; }