QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#377765 | #622. 多项式多点求值 | fragment | 0 | 62ms | 24668kb | C++17 | 4.0kb | 2024-04-05 17:36:32 | 2024-04-05 17:36:34 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
typedef unsigned long long ull;
const int mod=998244353,i2=(mod+1)>>1,i3=332748118,o=21;
int n,m,f[1<<o],q[1<<o],ans;
int t1[1<<o],t2[1<<o];
int fac[1<<o],ifac[1<<o],iv[1<<o];
inline int add(int x,int y){return x+y<mod?x+y:x+y-mod;}
inline int sub(int x,int y){return x<y?x+mod-y:x-y;}
inline int power(int a,int n){
int tp=1;
while(n){
if(n&1) tp=1ll*tp*a%mod;
a=1ll*a*a%mod,n>>=1;
}
return tp;
}
namespace poly{
int w[1<<o],r[1<<o],up,l;
inline void pre(int n){
up=1,l=0;
while(up<=n) up<<=1,l++;
for(int i=0;i<up;i++) r[i]=(r[i>>1]>>1)|((i&1)<<(l-1));
}
inline void init(){
const int w0=power(3,(mod-1)>>o);
w[1<<(o-1)]=1;
for(int i=(1<<(o-1))+1;i<(1<<o);i++) w[i]=1ll*w[i-1]*w0%mod;
for(int i=(1<<(o-1))-1;~i;i--) w[i]=w[i<<1];
}
void ntt(int *a, int n, bool op) {
static ull t[1 << o], x, y;
for (int i = 0; i != n; i += 2) {
x = a[r[i] >> (o - l)], y = a[r[i + 1] >> (o - l)];
t[i] = x + y, t[i + 1] = x + mod - y;
}
for (int l = 2; l != n; l <<= 1) {
if (l == (1 << 18))
for (ull *f = t; f != t + n; f++)
*f %= mod;
int *k = w + l;
for (ull *f = t; f != t + n; f += l)
for (int *j = k; j != k + l; j++, f++) {
ull x = *f, y = f[l] * *j % mod;
f[l] = x + mod - y, *f += y;
}
}
if (op) {
if (n == (1 << 18))
for (ull *f = t; f != t + n; f++)
*f %= mod;
for (int i = 0, x = mod - (mod >> l); i != n; i++)
a[i] = t[i] * x % mod;
reverse(a + 1, a + n);
} else
for (int i = 0; i != n; i++)
a[i] = t[i] % mod;
}
inline void mul(int *f,int n,int *g,int m,int *h,int q){
static int a[1<<o],b[1<<o];
pre(n+m);
memcpy(a,f,(n+1)<<2),memcpy(b,g,(m+1)<<2);
ntt(a,up,0),ntt(b,up,0);
for(int i=0;i<up;i++) h[i]=1ll*a[i]*b[i]%mod;
ntt(h,up,1);
fill(a,a+up,0),fill(b,b+up,0),fill(h+q+1,h+up,0);
}
inline void inv(int *a,int n,int *f){
static int x[1<<o];
int lt=(n+1)>>1;
if(!n){f[0]=power(a[0],mod-2);return;}
if(n==1) lt=0;
inv(a,lt,f);
pre(2*lt+n);
memcpy(x,a,(n+1)<<2);
ntt(f,up,0),ntt(x,up,0);
for(int i=0;i<up;i++) f[i]=1ll*f[i]*(2-1ll*x[i]*f[i]%mod+mod)%mod;
ntt(f,up,1);
fill(x,x+up,0),fill(f+n+1,f+up,0);
}
vector<int> v[240001];
inline void solve1(int i,int l,int r){
static int t1[1<<o],t2[1<<o];
if(l==r){v[i].push_back(1),v[i].push_back(sub(0,q[l]));return;}
int mid=(l+r)>>1;
solve1(i<<1,l,mid),solve1(i<<1|1,mid+1,r);
for(int j=0;j<=mid-l+1;j++) t1[j]=v[i<<1][j];
for(int j=0;j<=r-mid;j++) t2[j]=v[i<<1|1][j];
mul(t1,mid-l+1,t2,r-mid,t1,r-l+1),v[i].resize(r-l+2);
for(int j=0;j<=r-l+1;j++) v[i][j]=t1[j];
fill(t1,t1+r-l+2,0),fill(t2,t2+r-mid+1,0);
}
inline void solve2(int i,int l,int r,vector<int> f){
static int t1[1<<o],t2[1<<o];
if(l==r){
printf("%d\n",sub(ans,1ll*f[0]*v[i][1]%mod));
return;
}
int mid=(l+r)>>1,len=f.size()-1;
vector<int> f1,f2;
if(r-l<=f.size()) pre(len);
else pre(len+mid-l+1);
for(int j=0;j<=len;j++) t1[j]=f[j];
for(int j=0;j<=r-mid;j++) t2[j]=v[i<<1|1][j];
ntt(t1,up,0),ntt(t2,up,0);
for(int j=0;j<up;j++) t2[j]=1ll*t1[j]*t2[j]%mod;
ntt(t2,up,1);
for(int j=max(len-mid+l,0);j<=len;j++) f1.push_back(t2[j]);
fill(t2,t2+up,0);
for(int j=0;j<=mid-l+1;j++) t2[j]=v[i<<1][j];
ntt(t2,up,0);
for(int j=0;j<up;j++) t2[j]=1ll*t1[j]*t2[j]%mod;
ntt(t2,up,1);
for(int j=max(len-r+mid+1,0);j<=len;j++) f2.push_back(t2[j]);
fill(t2,t2+up,0),fill(t1,t1+up,0);
solve2(i<<1,l,mid,f1),solve2(i<<1|1,mid+1,r,f2);
}
}
int main(){
poly::init();
cin>>n>>m;
cin>>ans;for(int i=n-1;~i;i--) scanf("%d",f+i);
for(int i=1;i<=m;i++) scanf("%d",q+i);
poly::solve1(1,1,m);
for(int i=0;i<=m;i++) t1[i]=poly::v[1][i];
poly::inv(t1,n-1,t2);
poly::mul(f,n-1,t2,n-1,f,n-1);
vector<int> g;
for(int i=max(n-m,0);i<n;i++) g.push_back(f[i]);
poly::solve2(1,1,m,g);
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 7ms
memory: 17764kb
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:
575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 575336069 ...
result:
wrong answer 1st numbers differ - expected: '940122667', found: '575336069'
Test #2:
score: 0
Wrong Answer
time: 20ms
memory: 19088kb
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:
410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 410683245 ...
result:
wrong answer 1st numbers differ - expected: '683038054', found: '410683245'
Test #3:
score: 0
Wrong Answer
time: 62ms
memory: 24668kb
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:
536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 536696866 ...
result:
wrong answer 1st numbers differ - expected: '319541931', found: '536696866'
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...