QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#658727 | #9493. 路径计数 | zhouhuanyi | 100 ✓ | 4429ms | 407876kb | C++14 | 12.9kb | 2024-10-19 17:28:43 | 2024-10-19 17:28:48 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#define N 200002
#define M 524288
#define K 19
#define g 3
#define mod1 167772161
#define mod2 469762049
#define mod3 998244353
#define delta1 29562547
#define delta2 115990628
#define delta3 575867115
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
const __int128 sl=(__int128)(mod1)*mod2*mod3;
int c,n,m,mod,ans,A[N+1],B[N+1],C[N+1],D[N+1],E[N+1],F[N+1],wA[M+1],wB[M+1],dA[2][2][M+1],dB[2][2][M+1],dC[2][2][M+1],dp[N+1],num[M+1],length,rev[M+1];
unsigned long long invmod;
int fast_pow(int a,int b,int p)
{
int res=1,mul=a;
while (b)
{
if (b&1) res=1ll*res*mul%p;
mul=1ll*mul*mul%p,b>>=1;
}
return res;
}
int MD(int x)
{
return x>=mod?x-mod:x;
}
int MD2(int x)
{
return x<0?x+mod:x;
}
void Adder(int &x,int d)
{
x=x+d>=mod?x+d-mod:x+d;
return;
}
void Adder2(int &x,int d)
{
x=x+d<0?x+d+mod:x+d;
return;
}
int MDS1(int x)
{
return x>=mod1?x-mod1:x;
}
int MDS2(int x)
{
return x>=mod2?x-mod2:x;
}
int MDS3(int x)
{
return x>=mod3?x-mod3:x;
}
int MDS4(int x)
{
return x<0?x+mod1:x;
}
int MDS5(int x)
{
return x<0?x+mod2:x;
}
int MDS6(int x)
{
return x<0?x+mod3:x;
}
int mul(int a,int b)
{
long long c=1ll*a*b;
c-=(((__int128)(c)*invmod)>>63)*mod;
return c>=mod?c-mod:c;
}
struct reads
{
int d1,d2,d3;
};
reads zero,tA[M+1],tB[M+1],wn[M+1],wn2[M+1],W[M+1],sinv[M+1],qA[2][2][M+1],qB[2][2][M+1],qC[2][2][M+1];
reads operator + (reads a,reads b)
{
return (reads){MDS1(a.d1+b.d1),MDS2(a.d2+b.d2),MDS3(a.d3+b.d3)};
}
reads operator - (reads a,reads b)
{
return (reads){MDS4(a.d1-b.d1),MDS5(a.d2-b.d2),MDS6(a.d3-b.d3)};
}
reads operator * (reads a,reads b)
{
return (reads){1ll*a.d1*b.d1%mod1,1ll*a.d2*b.d2%mod2,1ll*a.d3*b.d3%mod3};
}
int calc(reads x)
{
return (((__int128)(1ll*x.d1*delta1%mod1)*mod2*mod3+(__int128)(1ll*x.d2*delta2%mod2)*mod1*mod3+(__int128)(1ll*x.d3*delta3%mod3)*mod1*mod2)%sl)%mod;
}
unsigned long long sdelta[M+1];
struct reads2
{
unsigned long long d1,d2,d3;
};
reads2 tdelta[M+1];
reads2 operator * (reads2 a,reads b)
{
return (reads2){a.d1*b.d1,a.d2*b.d2,a.d3*b.d3};
}
reads2 operator + (reads2 a,reads2 b)
{
return (reads2){a.d1+b.d1,a.d2+b.d2,a.d3+b.d3};
}
reads2 get_mod(reads2 a)
{
return (reads2){a.d1%mod1,a.d2%mod2,a.d3%mod3};
}
void NTT(int limit,int *s,int type)
{
int d;
for (int i=1;i<limit;++i) rev[i]=(rev[i>>1]>>1)|((i&1)?limit>>1:0);
for (int i=0;i<limit;++i) sdelta[rev[i]]=s[i];
if (type==1)
{
for (int i=2;i<=limit;i<<=1)
{
d=num[M/i];
for (int j=0;j<(i>>1);++j) W[j]=wn[j<<d];
for (int j=0;j+i-1<limit;j+=i)
for (int k=j;k<(j|(i>>1));++k)
d=sdelta[k|(i>>1)]*W[k-j].d3%mod3,sdelta[k|(i>>1)]=sdelta[k]+mod3-d,sdelta[k]+=d;
if (i>=(1<<17)||i==limit)
{
for (int j=0;j<=limit;++j) sdelta[j]%=mod3;
}
}
for (int i=0;i<=limit;++i) s[i]=sdelta[i];
}
else
{
for (int i=2;i<=limit;i<<=1)
{
d=num[M/i];
for (int j=0;j<(i>>1);++j) W[j]=wn2[j<<d];
for (int j=0;j+i-1<limit;j+=i)
for (int k=j;k<(j|(i>>1));++k)
d=sdelta[k|(i>>1)]*W[k-j].d3%mod3,sdelta[k|(i>>1)]=sdelta[k]+mod3-d,sdelta[k]+=d;
if (i>=(1<<17)||i==limit)
{
for (int j=0;j<=limit;++j) sdelta[j]%=mod3;
}
}
for (int i=0;i<=limit;++i) s[i]=sdelta[i]*sinv[limit].d3%mod3;
}
return;
}
void NTT_3m(int limit,reads *s,int type)
{
reads2 sw;
for (int i=1;i<limit;++i) rev[i]=(rev[i>>1]>>1)|((i&1)?limit>>1:0);
for (int i=0;i<limit;++i) tdelta[rev[i]]=(reads2){s[i].d1,s[i].d2,s[i].d3};
if (type==1)
{
for (int i=2,d;i<=limit;i<<=1)
{
d=num[M/i];
for (int j=0;j<(i>>1);++j) W[j]=wn[j<<d];
for (int j=0;j+i-1<limit;j+=i)
for (int k=j;k<(j|(i>>1));++k)
sw=get_mod(tdelta[k|(i>>1)]*W[k-j]),tdelta[k|(i>>1)]=tdelta[k]+(reads2){mod1-sw.d1,mod2-sw.d2,mod3-sw.d3},tdelta[k]=tdelta[k]+sw;
if (i>=(1<<17)||i==limit)
{
for (int j=0;j<=limit;++j) tdelta[j]=get_mod(tdelta[j]);
}
}
for (int i=0;i<limit;++i) s[i]=(reads){tdelta[i].d1,tdelta[i].d2,tdelta[i].d3};
}
else
{
for (int i=2,d;i<=limit;i<<=1)
{
d=num[M/i];
for (int j=0;j<(i>>1);++j) W[j]=wn2[j<<d];
for (int j=0;j+i-1<limit;j+=i)
for (int k=j;k<(j|(i>>1));++k)
sw=get_mod(tdelta[k|(i>>1)]*W[k-j]),tdelta[k|(i>>1)]=tdelta[k]+(reads2){mod1-sw.d1,mod2-sw.d2,mod3-sw.d3},tdelta[k]=tdelta[k]+sw;
if (i>=(1<<17)||i==limit)
{
for (int j=0;j<=limit;++j) tdelta[j]=get_mod(tdelta[j]);
}
}
for (int i=0;i<=limit;++i) tdelta[i]=get_mod(tdelta[i]*sinv[limit]),s[i]=(reads){tdelta[i].d1,tdelta[i].d2,tdelta[i].d3};
}
return;
}
vector<int>operator + (vector<int>a,vector<int>b)
{
if (a.empty()) return b;
if (b.empty()) return a;
if (a.size()<b.size()) swap(a,b);
for (int i=0;i<b.size();++i) Adder(a[i],b[i]);
return a;
}
vector<int>operator * (vector<int>a,vector<int>b)
{
if (a.empty()) return a;
if (b.empty()) return b;
vector<int>c(a.size()+b.size()-1);
if (min(a.size(),b.size())<=50)
{
for (int i=0;i<a.size();++i)
for (int j=0;j<b.size();++j)
Adder(c[i+j],mul(a[i],b[j]));
return c;
}
if (mod==998244353)
{
int limit=1;
while (limit<=a.size()+b.size()) limit<<=1;
for (int i=0;i<=limit;++i) wA[i]=wB[i]=0;
for (int i=0;i<a.size();++i) wA[i]=a[i];
for (int i=0;i<b.size();++i) wB[i]=b[i];
NTT(limit,wA,1),NTT(limit,wB,1);
for (int i=0;i<=limit;++i) wA[i]=1ll*wA[i]*wB[i]%mod3;
NTT(limit,wA,-1);
for (int i=0;i<c.size();++i) c[i]=wA[i];
return c;
}
else
{
int limit=1;
while (limit<=a.size()+b.size()) limit<<=1;
for (int i=0;i<=limit;++i) tA[i]=tB[i]=zero;
for (int i=0;i<a.size();++i) tA[i]=(reads){a[i]%mod1,a[i]%mod2,a[i]%mod3};
for (int i=0;i<b.size();++i) tB[i]=(reads){b[i]%mod1,b[i]%mod2,b[i]%mod3};
NTT_3m(limit,tA,1),NTT_3m(limit,tB,1);
for (int i=0;i<=limit;++i) tA[i]=tA[i]*tB[i];
NTT_3m(limit,tA,-1);
for (int i=0;i<c.size();++i) c[i]=calc(tA[i]);
return c;
}
}
vector<int>operator / (vector<int>a,vector<int>b)
{
vector<int>c(a.size()-b.size()+1);
if (min(b.size(),c.size())<=50)
{
for (int i=0;i<c.size();++i)
for (int j=0;j<b.size();++j)
Adder(c[i],mul(b[j],a[i+j]));
return c;
}
if (mod==998244353)
{
int limit=1;
while (limit<=a.size()) limit<<=1;
for (int i=0;i<=limit;++i) wA[i]=wB[i]=0;
for (int i=0;i<a.size();++i) wA[i]=a[i];
for (int i=0;i<b.size();++i) wB[b.size()-i]=b[i];
NTT(limit,wA,1),NTT(limit,wB,1);
for (int i=0;i<=limit;++i) wA[i]=1ll*wA[i]*wB[i]%mod3;
NTT(limit,wA,-1);
for (int i=0;i<c.size();++i) c[i]=wA[b.size()+i];
}
else
{
int limit=1;
while (limit<=a.size()) limit<<=1;
for (int i=0;i<=limit;++i) tA[i]=tB[i]=zero;
for (int i=0;i<a.size();++i) tA[i]=(reads){a[i]%mod1,a[i]%mod2,a[i]%mod3};
for (int i=0;i<b.size();++i) tB[b.size()-i]=(reads){b[i]%mod1,b[i]%mod2,b[i]%mod3};
NTT_3m(limit,tA,1),NTT_3m(limit,tB,1);
for (int i=0;i<=limit;++i) tA[i]=tA[i]*tB[i];
NTT_3m(limit,tA,-1);
for (int i=0;i<c.size();++i) c[i]=calc(tA[b.size()+i]);
}
return c;
}
vector<int>srev(int sz,vector<int>a)
{
a.resize(sz+1),reverse(a.begin(),a.end());
return a;
}
struct seg
{
struct node
{
int l,r;
vector<int>data;
vector<int>dst[2][2];
vector<int>sdata;
vector<int>sdata2;
};
node tree[(N<<2)+1];
void push_up(int k)
{
if (k!=1)
{
tree[k].data=tree[k<<1].data*tree[k<<1|1].data;
if (tree[k].r-tree[k].l+1<=50)
{
for (int i=0;i<=1;++i)
for (int j=0;j<=1;++j)
tree[k].dst[i][j]=tree[k<<1].dst[i][0]*tree[k<<1|1].dst[0][j]+tree[k<<1].dst[i][1]*tree[k<<1|1].dst[1][j];
}
else
{
int maxn=0;
for (int i=0;i<=1;++i)
for (int j=0;j<=1;++j)
tree[k].dst[i][j].resize(max(tree[k<<1].dst[i][0].size()+tree[k<<1|1].dst[0][j].size()-1,tree[k<<1].dst[i][1].size()+tree[k<<1|1].dst[1][j].size()-1)),maxn=max(maxn,(int)(tree[k].dst[i][j].size()));
if (mod==998244353)
{
int limit=1;
while (limit<=maxn) limit<<=1;
for (int i=0;i<=1;++i)
for (int j=0;j<=1;++j)
{
for (int t=0;t<=limit;++t) dA[i][j][t]=dB[i][j][t]=0;
for (int t=0;t<tree[k<<1].dst[i][j].size();++t) dA[i][j][t]=tree[k<<1].dst[i][j][t];
for (int t=0;t<tree[k<<1|1].dst[i][j].size();++t) dB[i][j][t]=tree[k<<1|1].dst[i][j][t];
NTT(limit,dA[i][j],1),NTT(limit,dB[i][j],1);
}
for (int i=0;i<=1;++i)
for (int j=0;j<=1;++j)
{
for (int k=0;k<=limit;++k) dC[i][j][k]=MD(1ll*dA[i][0][k]*dB[0][j][k]%mod+1ll*dA[i][1][k]*dB[1][j][k]%mod);
NTT(limit,dC[i][j],-1);
}
for (int i=0;i<=1;++i)
for (int j=0;j<=1;++j)
for (int t=0;t<tree[k].dst[i][j].size();++t)
tree[k].dst[i][j][t]=dC[i][j][t];
}
else
{
int limit=1;
while (limit<=maxn) limit<<=1;
for (int i=0;i<=1;++i)
for (int j=0;j<=1;++j)
{
for (int t=0;t<=limit;++t) qA[i][j][t]=qB[i][j][t]=zero;
for (int t=0;t<tree[k<<1].dst[i][j].size();++t) qA[i][j][t]=(reads){tree[k<<1].dst[i][j][t]%mod1,tree[k<<1].dst[i][j][t]%mod2,tree[k<<1].dst[i][j][t]%mod3};
for (int t=0;t<tree[k<<1|1].dst[i][j].size();++t) qB[i][j][t]=(reads){tree[k<<1|1].dst[i][j][t]%mod1,tree[k<<1|1].dst[i][j][t]%mod2,tree[k<<1|1].dst[i][j][t]%mod3};
NTT_3m(limit,qA[i][j],1),NTT_3m(limit,qB[i][j],1);
}
for (int i=0;i<=1;++i)
for (int j=0;j<=1;++j)
{
for (int k=0;k<=limit;++k) qC[i][j][k]=qA[i][0][k]*qB[0][j][k]+qA[i][1][k]*qB[1][j][k];
NTT_3m(limit,qC[i][j],-1);
}
for (int i=0;i<=1;++i)
for (int j=0;j<=1;++j)
for (int t=0;t<tree[k].dst[i][j].size();++t)
tree[k].dst[i][j][t]=calc(qC[i][j][t]);
}
}
}
return;
}
void build(int k,int l,int r)
{
tree[k].l=l,tree[k].r=r;
if (l==r)
{
tree[k].data={B[l],1};
if (l) tree[k].dst[0][1]={MD2(-1ll*A[l-1]*D[l]%mod)};
tree[k].dst[1][0]={1},tree[k].dst[1][1]={MD2(-C[l]),1};
return;
}
int mid=(l+r)>>1;
build(k<<1,l,mid),build(k<<1|1,mid+1,r),push_up(k);
return;
}
void get(int k)
{
if (tree[k].l==tree[k].r) return;
int mid=(tree[k].l+tree[k].r)>>1;
tree[k<<1].sdata=tree[k].sdata,tree[k<<1].sdata2=tree[k].sdata2;
tree[k<<1].sdata.resize(mid-tree[k].l+1),tree[k<<1].sdata2.resize(mid-tree[k].l+1);
tree[k<<1|1].sdata=tree[k].sdata*srev(mid-tree[k].l+1,tree[k<<1].dst[0][0])+tree[k].sdata2*srev(mid-tree[k].l+1,tree[k<<1].dst[1][0]),tree[k<<1|1].sdata2=tree[k].sdata*srev(mid-tree[k].l+1,tree[k<<1].dst[0][1])+tree[k].sdata2*srev(mid-tree[k].l+1,tree[k<<1].dst[1][1]);
tree[k<<1|1].sdata.resize(tree[k].r-mid),tree[k<<1|1].sdata2.resize(tree[k].r-mid);
get(k<<1),get(k<<1|1);
return;
}
void solve(int k,vector<int>p,vector<int>q)
{
if (tree[k].l==tree[k].r)
{
Adder2(dp[tree[k].l],-q[0]);
return;
}
int mid=(tree[k].l+tree[k].r)>>1;
vector<int>sp=p;
vector<int>sq=q;
vector<int>wp;
vector<int>wq;
vector<int>sr(mid-tree[k].l+1);
sp.resize(mid-tree[k].l+1),sq.resize(mid-tree[k].l+1),solve(k<<1,sp,sq);
for (int i=tree[k].l;i<=mid;++i) sr[i-tree[k].l]=dp[i];
wp=sr*tree[k].sdata,wq=sr*tree[k].sdata2;
wp.resize(p.size()),wq.resize(q.size());
for (int i=0;i<wp.size();++i) Adder(p[i],wp[i]);
for (int i=0;i<wq.size();++i) Adder(q[i],wq[i]);
sp=p/tree[k<<1].dst[0][0]+q/tree[k<<1].dst[1][0];
sq=p/tree[k<<1].dst[0][1]+q/tree[k<<1].dst[1][1];
sp.resize(tree[k].r-mid),sq.resize(tree[k].r-mid),solve(k<<1|1,sp,sq);
return;
}
void solve2(int k,vector<int>p)
{
if (tree[k].l==tree[k].r)
{
Adder(ans,mul(p[0],E[tree[k].l]));
return;
}
vector<int>sp=p;
sp.resize(tree[k<<1].r-tree[k<<1].l+1),solve2(k<<1,sp),solve2(k<<1|1,p/tree[k<<1].data);
return;
}
};
seg T;
int main()
{
reads w,rest;
sinv[1]=(reads){1,1,1};
for (int i=2;i<=M;i<<=1) num[i]=++length,sinv[i]=(reads){fast_pow(i,mod1-2,mod1),fast_pow(i,mod2-2,mod2),fast_pow(i,mod3-2,mod3)};
w=(reads){fast_pow(g,(mod1-1)/M,mod1),fast_pow(g,(mod2-1)/M,mod2),fast_pow(g,(mod3-1)/M,mod3)},rest=(reads){1,1,1};
for (int i=0;i<(M>>1);++i,rest=rest*w) wn[i]=rest;
w=(reads){fast_pow(g,(mod1-1)/M*(M-1),mod1),fast_pow(g,(mod2-1)/M*(M-1),mod2),fast_pow(g,(mod3-1)/M*(M-1),mod3)},rest=(reads){1,1,1};
for (int i=0;i<(M>>1);++i,rest=rest*w) wn2[i]=rest;
c=read(),n=read(),m=read(),mod=read(),invmod=(1ull<<63)/mod;
for (int i=0;i<=m-1;++i) A[i]=read();
for (int i=0;i<=n-1;++i) B[i]=read();
for (int i=0;i<=m;++i) C[i]=read();
for (int i=1;i<=m;++i) D[i]=read();
for (int i=0;i<=n;++i) E[i]=read();
for (int i=0;i<=m;++i) F[i]=read();
T.build(1,0,n),T.tree[1].sdata2={1},T.get(1);
for (int i=0,res=1;i<=n;++i,res=mul(res,A[i-1])) dp[i]=mul(res,F[i]);
vector<int>sp(n+1);
vector<int>sq(n+1);
T.solve(1,sp,sq);
vector<int>p(n+1);
for (int i=0;i<=n;++i) p[i]=dp[i];
T.solve2(1,p),printf("%d\n",ans);
return 0;
}
詳細信息
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 81ms
memory: 205204kb
input:
1 5000 5000 998244353 121811167 379924090 361631583 174189813 559424693 889647308 193102812 469875055 32237660 96186933 624360154 404866088 859165067 748410791 926700198 368632735 476560636 798138824 17883437 712872225 448819400 33122704 572152288 627010263 336722521 775918346 465722630 681224329 60...
output:
698779876
result:
ok single line: '698779876'
Test #2:
score: 3
Accepted
time: 74ms
memory: 209100kb
input:
1 4999 4919 998244353 380477138 780960797 787883474 484131625 121182688 933501638 947532778 257948759 108946829 468475856 5564419 677097370 766236309 678789875 533319074 885579006 769287005 710724535 260200529 599758240 380918586 216469888 78561030 325936496 189815268 268769489 232850763 937923688 9...
output:
475720945
result:
ok single line: '475720945'
Test #3:
score: 3
Accepted
time: 81ms
memory: 199648kb
input:
1 4995 4997 998244353 267305461 291432119 107593765 530653184 893921215 15414240 991509792 601027626 313017049 827685069 650321853 385956762 140661695 303322469 142427516 910941336 265371405 731125266 512689773 723594553 552396112 379799950 43662480 666390792 938399292 144960568 817187890 428532063 ...
output:
568578871
result:
ok single line: '568578871'
Subtask #2:
score: 5
Accepted
Test #4:
score: 5
Accepted
time: 4329ms
memory: 407316kb
input:
2 200000 200000 998244353 903563506 433239074 632684755 970178226 831892753 932120646 157832416 517140217 296101978 998244343 850946564 2367119 708278025 376919151 752106478 994362560 806760771 672325565 9 958330492 343658496 153627310 330649130 983441587 829707074 135609242 706388812 325297147 4972...
output:
108905794
result:
ok single line: '108905794'
Test #5:
score: 5
Accepted
time: 4355ms
memory: 400420kb
input:
2 199910 194100 998244353 587911377 573048398 832688590 809066619 524442920 218487661 649170169 8 150333233 204150153 800582862 464558080 291668841 361834956 998244344 998244349 806341682 775965963 459031329 867640103 425129750 7 998244343 274941091 809744915 443910210 859200100 998244350 725497297 ...
output:
597176160
result:
ok single line: '597176160'
Test #6:
score: 5
Accepted
time: 3061ms
memory: 348192kb
input:
2 150810 200000 998244353 288330007 105173193 991831123 698131025 301828280 273289882 387551340 542768677 115972971 425381688 811911805 962095963 566257196 435928108 337873530 109252306 933737641 967531573 29209951 787608009 497111219 315932660 878605444 903737754 260092904 447237039 37123388 594371...
output:
78643368
result:
ok single line: '78643368'
Subtask #3:
score: 8
Accepted
Test #7:
score: 8
Accepted
time: 4351ms
memory: 407324kb
input:
3 200000 200000 998244353 493605813 622283646 579332647 528537957 211102509 336893985 106292723 166710741 443808575 180234697 744331593 252016663 693453924 975202110 519712748 174749950 250990381 584528219 619047448 641168296 914918741 785005029 433175528 400547992 845115512 278159630 227330862 6407...
output:
144815343
result:
ok single line: '144815343'
Test #8:
score: 8
Accepted
time: 4324ms
memory: 407668kb
input:
3 200000 199996 998244353 742 699221406 301 364485093 804 294 873 282584633 204 882 889 438104412 349 737559671 152908512 490 206 11 613 175 155 659898955 983 206756334 273919067 843 898 359154783 360 612 201572138 207697004 396 482 136 361 339 831490112 279585283 516749439 318 198386232 69807322 72...
output:
758876599
result:
ok single line: '758876599'
Test #9:
score: 8
Accepted
time: 36ms
memory: 167488kb
input:
3 1 200000 998244353 734 796 543458399 920002767 990425370 338 107321680 90089647 557777271 434728777 503 709 616 850 448 884 143526194 299065437 45361809 666577969 923 492965257 850 229 769 183867189 675 463141085 791 281 718 763 240353338 711 671313626 203252664 888743426 450 223 446 542052402 565...
output:
53421494
result:
ok single line: '53421494'
Test #10:
score: 8
Accepted
time: 4364ms
memory: 397680kb
input:
3 200000 1 998244353 277786488 264242127 2 319061241 5 8 2 1 51038317 673171629 267552091 920379441 5 880796442 618282833 514210179 9 8 67744028 9 1 691195881 92394487 719900388 638641507 5 663287704 4 579997250 985749664 984980853 4 519857232 4 735668111 3 7 360023171 7 7 234677046 359140782 8 5227...
output:
140453572
result:
ok single line: '140453572'
Subtask #4:
score: 8
Accepted
Dependency #2:
100%
Accepted
Test #11:
score: 8
Accepted
time: 4413ms
memory: 407744kb
input:
4 200000 200000 998244353 199752876 397435299 166254444 779278347 182416898 901682085 69090988 738092954 712758505 681482091 950425501 897402866 870967623 36849705 515322829 172446310 900429861 34423824 785446470 553333476 938968413 86270822 973639556 431435054 741273084 677434142 222677171 61928101...
output:
65201275
result:
ok single line: '65201275'
Test #12:
score: 8
Accepted
time: 4350ms
memory: 397792kb
input:
4 199996 2000 998244353 865 499 31904732 259114092 967550739 255 785 143545371 699 573 216 789 553653892 329548961 451423632 886 741679575 78720133 464611720 972 242 869 294933191 351 788310280 697 861990346 731 734 701 407 401383418 835 189335197 668 758851074 250436747 962105421 562203389 11011899...
output:
85153184
result:
ok single line: '85153184'
Test #13:
score: 8
Accepted
time: 656ms
memory: 232000kb
input:
4 40000 190000 998244353 953 586890334 906 161 524210942 327745937 100 231 970 63891350 28 370040454 628796638 275 239621470 708518643 995 351 376514813 814869235 66 742 561 483786281 5379525 603 608 274128226 256 844 662 445297819 123782163 920 957935561 621339377 26129412 763585646 451 911 5350051...
output:
99807982
result:
ok single line: '99807982'
Subtask #5:
score: 5
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Test #14:
score: 5
Accepted
time: 4333ms
memory: 398692kb
input:
5 200000 200000 998244353 357 270 635 81 18806969 807 433 242 242 154 347094190 96 953 893447557 497 265754515 220901127 205 958 488 212420388 457 799989458 726134433 547661079 946786926 891 955400819 664511484 701 155 791 4 845 954462573 536216065 136 54 251 481 584310172 389122260 34 527707943 300...
output:
366841924
result:
ok single line: '366841924'
Test #15:
score: 5
Accepted
time: 4311ms
memory: 407460kb
input:
5 199999 190000 998244353 930048626 861740403 534792638 856 178 908419417 742 685 40557520 132 779489457 792 468990716 153965694 395450527 688 398541680 651 789664707 703746126 579 588989999 936017101 652728925 314526790 297 962 771009949 626 192587923 377598397 654 459 187173523 857466261 567 73215...
output:
755407887
result:
ok single line: '755407887'
Subtask #6:
score: 15
Accepted
Test #16:
score: 15
Accepted
time: 4359ms
memory: 407340kb
input:
6 200000 200000 998244353 401806059 107033001 530043262 862506025 263940497 48524969 232075248 849682830 420464058 64900333 394986647 954304290 957385577 86269798 579307969 896967626 230611640 527078096 39773429 402432856 495204529 272090833 100466767 562115973 196636941 736050044 580541546 81233872...
output:
562220526
result:
ok single line: '562220526'
Test #17:
score: 15
Accepted
time: 4290ms
memory: 396648kb
input:
6 190000 180000 998244353 331419431 585273774 326021268 911984877 504951700 663 667 967180428 535316997 888573230 112066317 286249963 593 994 230 367194808 906865758 946973557 921 1 302880572 377068830 444057418 953 1000 946 906 274661283 90 345429012 719 547222223 806 856 911 970 110923264 26390908...
output:
467130256
result:
ok single line: '467130256'
Subtask #7:
score: 16
Accepted
Dependency #1:
100%
Accepted
Test #18:
score: 16
Accepted
time: 4365ms
memory: 407088kb
input:
7 200000 20000 998244353 869285118 18064361 457499026 292378234 45941854 157946840 586178769 392380503 830348035 141601898 591275235 100919004 399285791 115436998 586990272 287976693 795031696 836945332 895793688 432697639 828280269 714678411 137052352 516420393 730089484 911809696 350536206 8175289...
output:
809172057
result:
ok single line: '809172057'
Test #19:
score: 16
Accepted
time: 4303ms
memory: 397704kb
input:
7 200000 19810 998244353 828902663 612852451 425506197 233025854 319333441 952074173 717042023 949076193 83452305 763673071 41376007 272593034 356441893 361994505 185035237 266625028 550156798 775373755 727044232 359307823 648601627 384158945 313651668 746883203 321976362 307448064 64684150 4186580 ...
output:
560874322
result:
ok single line: '560874322'
Test #20:
score: 16
Accepted
time: 28ms
memory: 196456kb
input:
7 1000 9996 998244353 233393388 143 900 282 622 588 259300855 18722608 81440606 388097181 802 119 117027019 445 244 220 321165142 193445923 884359675 276 671093341 934763449 844222944 251 190039071 208 521 758 621 722 370522729 731 968984566 656850987 42380471 798 292 324 609 606 400 210 785 816 863...
output:
964458165
result:
ok single line: '964458165'
Test #21:
score: 16
Accepted
time: 4364ms
memory: 397968kb
input:
7 200000 9919 998244353 127286538 946789972 892201793 335420070 263695484 170118086 108765927 699100677 678757948 552873985 565640470 952666657 645394702 560901257 95959026 804657734 83330667 185533959 520165719 246753496 769277586 697870667 659358703 318912135 658640680 810790915 492140504 62924551...
output:
269104705
result:
ok single line: '269104705'
Subtask #8:
score: 16
Accepted
Dependency #6:
100%
Accepted
Test #22:
score: 16
Accepted
time: 4429ms
memory: 407876kb
input:
8 200000 200000 998244353 476657058 608590028 176876078 188969399 496243267 200861994 525765121 157833667 112147905 888494665 86463084 3240780 881100059 209383369 616595337 943058640 18341235 731579551 223351112 539615902 3395185 187153519 82693410 67612463 680802074 217978817 9323483 678602864 3453...
output:
474782296
result:
ok single line: '474782296'
Test #23:
score: 16
Accepted
time: 4361ms
memory: 407484kb
input:
8 199997 170000 998244353 505360294 8 975 463 168746690 820247591 120436643 410462769 12959063 167531115 300 621 191294387 22 410 679 782371812 449088425 162807445 835 149638206 858 65 581 12 959 310569501 119222808 476951257 403 646 312711442 530 858755892 671888747 458 412 247 114 230 422058417 22...
output:
763867893
result:
ok single line: '763867893'
Test #24:
score: 16
Accepted
time: 4264ms
memory: 396916kb
input:
8 190000 199996 998244353 749 721817394 27 645 439406479 108090145 550371723 420419950 461 779 412458565 731555989 681 322 304994251 402 74 874226263 674 346 114 126 838 687147645 321419751 420 198508289 341 807392775 960572742 60398571 708697994 880 573 77 521 699 200251635 886 5466957 908 569 96 3...
output:
446047127
result:
ok single line: '446047127'
Test #25:
score: 16
Accepted
time: 4378ms
memory: 407748kb
input:
8 200000 200000 998244353 673 387 272 59 192173777 764 170183158 746432263 207 267 390 400 524 13 968340991 557741817 104800071 932539161 695618609 496396588 645 847701916 398 59229077 279708783 178114129 477 170 819671340 467175001 430861597 292163679 405 189 67855913 794507178 990487692 197409331 ...
output:
927461446
result:
ok single line: '927461446'
Test #26:
score: 16
Accepted
time: 4380ms
memory: 398560kb
input:
8 199999 190000 998244353 190706062 888680627 83397214 6 494083839 9 5 71812818 661044051 2 851345196 4 5 9 1 655271434 10 9 4 9 6 103209989 4 9 976030578 655935000 623342477 1 206077679 7 10 8 6 9 7 298401605 892975523 8 267432364 53188239 70291367 142791981 531492153 5 5 672326478 962867181 7 8679...
output:
170212793
result:
ok single line: '170212793'
Subtask #9:
score: 9
Accepted
Dependency #5:
100%
Accepted
Dependency #7:
100%
Accepted
Dependency #8:
100%
Accepted
Test #27:
score: 9
Accepted
time: 4349ms
memory: 400940kb
input:
9 200000 200000 998244353 886612651 387277498 222689570 149684757 801547216 39958935 61994466 279732876 910669986 673110448 242227789 281852762 124220159 702603904 242726522 761430846 261708466 14196264 198147684 71130471 96539799 886809411 454014179 438893638 437708905 533400975 385272485 461115839...
output:
653639881
result:
ok single line: '653639881'
Test #28:
score: 9
Accepted
time: 4343ms
memory: 397308kb
input:
9 199000 199990 998244353 929566148 214291485 906544066 298915999 689760706 271699591 482768561 898907851 81802523 554994538 134064180 501518029 641765774 423311402 134116703 391491198 791826482 649073874 696499611 279773162 697654068 669577487 356335067 571197676 194446272 321902950 667228720 31535...
output:
790075420
result:
ok single line: '790075420'
Test #29:
score: 9
Accepted
time: 4358ms
memory: 406888kb
input:
9 199997 199992 998244353 131543484 131291289 593343835 383688404 614251659 28042347 794277226 944988995 90198501 227326291 300776651 558115109 476201534 78151684 536357291 264046767 946044015 398569226 176484997 28421208 648281543 235639450 776266080 616245182 623867397 523564530 864964454 40378887...
output:
483850208
result:
ok single line: '483850208'
Test #30:
score: 9
Accepted
time: 4383ms
memory: 398888kb
input:
9 200000 200000 998244353 745599216 859346500 634928637 690647766 10273176 338563878 7698219 743763863 718373315 189069600 879813230 122401277 976417985 98413473 210957679 595554610 710895015 273465866 711019517 695658890 236226376 740332195 711573064 388099079 794053021 135899585 924688794 41508470...
output:
503071975
result:
ok single line: '503071975'
Test #31:
score: 9
Accepted
time: 4324ms
memory: 400752kb
input:
9 200000 200000 998244353 998244284 998243397 998243865 998244160 998243619 998244095 998243530 998244257 998243534 998243564 998243583 998244164 998244147 998244000 998243730 998243737 998243628 998243528 998243829 998244222 998243852 998244137 998243563 998244120 998244207 998243409 998243839 9982...
output:
359574540
result:
ok single line: '359574540'
Subtask #10:
score: 15
Accepted
Dependency #1:
100%
Accepted
Test #32:
score: 15
Accepted
time: 4291ms
memory: 332780kb
input:
10 100000 100000 856853193 287061150 779504426 21691247 494814415 381655016 536089292 240188530 458291018 332927950 428352746 351529999 258956585 651084688 268523951 338285674 719419445 165275422 367200319 35308342 563282834 763880581 117326555 284413760 207571906 703023023 622478929 212959189 34094...
output:
304611769
result:
ok single line: '304611769'
Test #33:
score: 15
Accepted
time: 4283ms
memory: 297760kb
input:
10 99996 99997 653184000 466780448 535452791 494399809 577708013 478667201 237421741 395730779 45154159 498661837 490060453 482125361 487937293 157588691 293334157 321521203 332545607 379473949 284060041 248007589 586611611 608983811 260677141 333698719 223055627 87263221 229163593 28977457 18266932...
output:
420309862
result:
ok single line: '420309862'
Test #34:
score: 15
Accepted
time: 4308ms
memory: 330568kb
input:
10 99999 90909 993244353 662162902 368244673 342499724 545049098 136506796 132436037 290223682 406097143 860074972 162846125 724197628 121400297 113044490 571603127 804520820 716276159 223707430 992306213 67492417 849796319 195226523 811081288 878152369 146106266 297648880 82596461 645880612 8404165...
output:
988875128
result:
ok single line: '988875128'
Test #35:
score: 15
Accepted
time: 4275ms
memory: 330508kb
input:
10 99939 99191 619701811 471592989 63987447 296515528 434393809 417522560 235747800 318375577 493346545 293408357 502026258 384261946 2633459 211063149 511625485 317222583 159798065 478842502 299419646 341333878 214971597 216954473 284823472 514945706 380116339 499467361 423121831 184869643 21045491...
output:
170476426
result:
ok single line: '170476426'
Test #36:
score: 15
Accepted
time: 4298ms
memory: 332872kb
input:
10 100000 100000 761140380 535267356 745353877 500892797 72821999 206782603 274141687 238741351 705785503 33076811 685974761 141313651 487155329 758438399 740389121 653321807 242325899 271642201 382683239 328197257 364100593 754134917 394678301 686138447 541301689 274967291 220724737 688145503 38492...
output:
389683306
result:
ok single line: '389683306'