QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#421720 | #622. 多项式多点求值 | light_ink_dots | 60 | 136ms | 76832kb | C++14 | 4.8kb | 2024-05-26 00:54:08 | 2024-05-26 00:54:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353,G=3;
using ll = long long;
ll w[1<<21],Finv[1<<21],F[1<<21],Inv[1<<21];
ll qpow(ll a,ll b){
ll ret=1;
while(b){
if(b&1) ret=ret*a%mod;
a=a*a%mod;b>>=1;
}return ret;
}
void init(){
int n=1<<20;
F[0]=Finv[0]=1;
for(int i=1;i<=n;i++) F[i]=F[i-1]*i%mod;Finv[n]=qpow(F[n],mod-2);
for(int i=n-1;i>=0;i--) Finv[i]=Finv[i+1]*(i+1)%mod;
for(int i=1;i<=n;i++) Inv[i]=Finv[i]*F[i-1]%mod;
for(int mid=1;mid<(1<<21);mid<<=1){
ll wn=qpow(G,(mod-1)/(mid*2));
w[mid]=1;
for(int k=1;k<mid;k++) w[mid+k]=w[mid+k-1]*wn%mod;
}
}
void upd(ll &x){
x-=(x>=mod?mod:0);
}
struct poly{
vector<ll>a;
// size -> 最高项次数
// resize -> mod x^{n+1}
int size()const{return (int)(a.size())-1;}
void resize(int n){a.resize(n+1);}
poly Mod(int n){
poly c=(*this);
c.resize(n-1);
return c;
}
void reduce(int n){
if(size()>n) resize(n);
}
poly(){}
poly(int n){resize(n);}
poly(const vector<ll>&_a){a=_a;}
ll&operator[](int n){return a[n];}
void dif(int lim){
a.resize(lim);
for(int mid=1;mid<lim;mid<<=1){
for(int j=0;j<lim;j+=(mid<<1)){
ll x=a[j],y=a[j+mid];
upd(a[j]=x+y);
upd(a[j+mid]=x-y+mod);
for(int k=1;k<mid;k++){
ll x=a[j+k],y=a[j+k+mid]*(mod-w[2*mid-k])%mod;
upd(a[j+k]=x+y);
upd(a[j+k+mid]=x-y+mod);
}
}
}
ll inv=qpow(lim,mod-2);
for(int i=0;i<lim;i++)a[i]=a[i]*inv%mod;
}
void dit(int lim){
a.resize(lim);
for(int mid=(lim>>1);mid>=1;mid>>=1){
for(int j=0;j<lim;j+=(mid<<1)){
for(int k=0;k<mid;k++){
ll x=a[j+k],y=a[j+k+mid];
upd(a[j+k]=x+y);
(a[j+k+mid]=(x-y+mod)*w[mid+k])%=mod;
}
}
}
}
poly operator *(const poly &b)const{
poly c=(*this),d=b;
int len=c.size()+d.size(),lim=1;
while(lim<=len) lim<<=1;
c.dit(lim),d.dit(lim);
for(int i=0;i<lim;i++) c[i]=c[i]*d[i]%mod;
c.dif(lim);c.resize(len);
return c;
}
poly operator +(const poly &b){
poly c=(*this),d=b;int len=max(c.size(),d.size());
c.resize(len),d.resize(len);
for(int i=0;i<=len;i++)upd(c[i]+=d[i]);
return c;
}
poly operator -(const poly &b){
poly c=(*this),d=b;int len=max(c.size(),d.size());
c.resize(len),d.resize(len);
for(int i=0;i<=len;i++)upd(c[i]=c[i]-d[i]+mod);
return c;
}
// mod x^{lim} init 2*Max_len
poly inv(int lim){
if(lim==1){
return vector<ll>{qpow(a[0],mod-2)};
}
poly c=(*this),ans;
c.a.resize(lim);
int l=(lim+1)/2;
poly inv=c.inv(l);
ans=(inv+inv)-(inv*inv)*c;
ans.a.resize(lim);
return ans;
}
poly ln(int lim){
poly r=inv(lim-1),ans(lim-1),d=(*this);
d.resize(lim);
for(int i=0;i<lim;i++) d[i]=d[i+1]*(i+1)%mod;
r=r*d;
for(int i=1;i<lim;i++) ans[i]=r[i-1]*Inv[i]%mod;
return ans;
}
poly exp(int lim){
if(lim==1){
return vector<ll>{1};
}
int len=(lim+1)/2;
poly h=(*this);h.resize(lim-1);
poly f0=h.exp(len);
poly res=f0-(f0.ln(lim)-h)*f0;
res.resize(lim-1);
return res;
}
poly dot(const poly &b){
poly c=*this;
reverse(c.a.begin(),c.a.end());
c=(c*b);c.resize(size());
reverse(c.a.begin(),c.a.end());
return c;
}
};
poly t[(64000<<2)+10],g[(64000<<2)+10];
//Input f degree n ; m's point : a
ll a[64010],ans[64010];
int n,m;
void solve(int p,int l,int r){
if(l==r){
t[p]=poly({1,-a[l]});return ;
}
int mid=l+r>>1;
solve(p<<1,l,mid),solve(p<<1|1,mid+1,r);
t[p]=t[p<<1]*t[p<<1|1];
}
void solve2(int p,int l,int r){
if(l==r){
ans[l]=(g[p][0]+mod)%mod;
return ;
}
int mid=l+r>>1;
g[p<<1]=g[p].dot(t[p<<1|1]).Mod(mid-l+1);
g[p<<1|1]=g[p].dot(t[p<<1]).Mod(r-mid);
solve2(p<<1,l,mid),solve2(p<<1|1,mid+1,r);
}
void Multival(poly &f,int n,int m){
solve(1,1,m);
g[1]=f.dot(t[1].inv(n+1)).Mod(m);
solve2(1,1,m);
}
int main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
init();
int n,m;
cin>>n>>m;
n--;
poly f(n);
for(int i=0;i<=n;i++) cin>>f[i];
for(int i=1;i<=m;i++) cin>>a[i];
Multival(f,n,m);
for(int i=1;i<=m;i++) cout<<ans[i]<<"\n";
}
詳細信息
Test #1:
score: 20
Accepted
time: 32ms
memory: 63228kb
input:
100 94 575336069 33153864 90977269 80162592 25195235 334936051 108161572 14050526 356949084 797375084 805865808 286113858 995555121 938794582 458465004 379862532 563357556 293989886 273730531 13531923 113366106 126368162 405344025 443053020 475686818 734878619 338356543 661401660 834651229 527993675...
output:
940122667 397187437 905033404 346709388 146347009 49596361 125616024 966474950 693596552 162411542 248699477 217639076 254290825 963991654 951375739 431661136 587466850 933820245 135676159 683994808 821695954 675479292 463904298 15085475 183389374 976945620 668527277 98940366 909505808 904450031 968...
result:
ok 94 numbers
Test #2:
score: 20
Accepted
time: 31ms
memory: 65684kb
input:
5000 4999 410683245 925831211 726803342 144364185 955318244 291646122 334752751 893945905 484134283 203760731 533867267 813509277 491860093 413174124 584582617 594704162 976489328 978500071 196938934 628117769 169796671 858963950 562124570 582491326 647830593 238623335 20782490 674939336 656529076 2...
output:
683038054 713408290 776843174 52275065 602085453 905088100 991748340 720305324 831850056 296147844 79380797 882313010 941965313 987314872 363655479 380838721 51243733 165728533 592641557 679475455 651115426 60492203 787012426 247557193 136399242 484592897 908383514 735275879 648228244 443933835 5504...
result:
ok 4999 numbers
Test #3:
score: 20
Accepted
time: 136ms
memory: 76832kb
input:
30000 29995 536696866 881441742 356233606 594487396 991820796 695996817 7219464 149265950 843761437 329761701 260625152 80366362 598729314 133794090 12808683 67477659 320740422 878134577 879383179 940923483 660160621 18082378 886078389 524050341 35092018 137623841 988429688 258507355 138475726 75726...
output:
319541931 71523627 374970852 25715597 36244629 300490421 920015579 97305810 949802809 507599156 733158280 569689405 234576135 266469534 141265915 989761030 221701009 895284489 707865101 547950933 844193939 688358883 642066256 113618699 877631874 804170817 455115375 47621629 66017800 747477619 281472...
result:
ok 29995 numbers
Test #4:
score: 0
Runtime Error
input:
100000 99989 703908936 826436271 431732352 607460686 960390248 897906950 506352459 662618885 172508812 713410533 704313866 156459539 879660919 98030681 46358006 400134234 121190289 498201666 616888945 210891377 39623412 687350951 269444705 980768130 381802923 553892268 644461704 287608268 554761733 ...
output:
result:
Test #5:
score: 0
Runtime Error
input:
1000000 999998 326289172 459965021 432610030 381274775 890620650 133203219 755508578 820410129 100497878 978894337 34545975 484258543 341383383 556328539 705716773 985485996 201697555 806763870 456757110 445252781 501965590 655584951 516373423 475444481 554722275 106826011 433893131 385018453 687541...