QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#663067 | #9493. 路径计数 | ucup-team1004 | 85 | 8431ms | 263448kb | C++17 | 10.5kb | 2024-10-21 12:43:28 | 2024-10-21 12:43:30 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned long long;
const int mod=998244353;
ll qpow(ll x,ll y=mod-2,ll ans=1){
static const int Mod=mod-1;
y=(y%Mod+Mod)%Mod;
for(;y;(x*=x)%=mod,y>>=1)if(y&1)(ans*=x)%=mod;
return ans;
}
namespace Poly{
const int N=1<<21,g=[](){
vector<int>p;
int x=mod-1;
for(int i=2;i*i<=x;i++){
if(x%i==0)p.push_back(i);
for(;x%i==0;x/=i);
}
if(x>1)p.push_back(x);
auto chk=[&](int x){
for(int y:p){
if(qpow(x,(mod-1)/y)==1)return 0;
}
return 1;
};
int res=1;
for(;!chk(res);res++);
return res;
}();
int lim,rev[N],A[N],B[N],pw[N];
void init(int n){
for(lim=1;lim<n;lim<<=1);
for(int i=1;i<lim;i++)rev[i]=rev[i>>1]>>1|(i&1?lim>>1:0);
}
void Init(){
int x=qpow(g,(mod-1)/N);
pw[N/2]=1;
for(int i=N/2+1;i<N;i++)pw[i]=1ll*pw[i-1]*x%mod;
for(int i=N/2-1;i;i--)pw[i]=pw[i<<1];
}
struct Init_{
Init_(){Init();}
}init_;
namespace Public{
using poly=vector<int>;
poly Ifac(int n){
poly ifac(n,1);
for(int i=2;i<n;i++)ifac[i]=1ll*ifac[mod%i]*(mod-mod/i)%mod;
for(int i=1;i<n;i++)ifac[i]=1ll*ifac[i]*ifac[i-1]%mod;
return ifac;
}
void NTT(int *f,int op){
static unsigned long long a[N];
for(int i=0;i<lim;i++)a[i]=f[rev[i]];
for(int len=1,x;len<lim;len<<=1){
for(int i=0;i<lim;i+=len<<1){
for(int j=0;j<len;j++){
x=a[i|j|len]*pw[len|j]%mod;
a[i|j|len]=a[i|j]+mod-x,a[i|j]+=x;
}
}
if(len>>16&1){
for(int i=0;i<lim;i++)a[i]%=mod;
}
}
for(int i=0;i<lim;i++)f[i]=a[i]%mod;
if(op<0){
reverse(f+1,f+lim);
int x=qpow(lim);
for(int i=0;i<lim;i++)f[i]=1ll*f[i]*x%mod;
}
}
void NTT(poly &f,int op){
static unsigned long long a[N];
for(int i=0;i<lim;i++)a[i]=f[rev[i]];
for(int len=1,x;len<lim;len<<=1){
for(int i=0;i<lim;i+=len<<1){
for(int j=0;j<len;j++){
x=a[i|j|len]*pw[len|j]%mod;
a[i|j|len]=a[i|j]+mod-x,a[i|j]+=x;
}
}
if(len>>16&1){
for(int i=0;i<lim;i++)a[i]%=mod;
}
}
for(int i=0;i<lim;i++)f[i]=a[i]%mod;
if(op<0){
reverse(f.begin()+1,f.begin()+lim);
int x=qpow(lim);
for(int i=0;i<lim;i++)f[i]=1ll*f[i]*x%mod;
}
}
poly operator * (const poly &a,const poly &b){ // poly multiple
int n=a.size(),m=b.size(),k=n+m-1;
poly c(k);
if(min(n,m)<=50){
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
c[i+j]=(c[i+j]+1ll*a[i]*b[j])%mod;
}
}
return c;
}
init(k);
copy(all(a),A),fill(A+n,A+lim,0);
copy(all(b),B),fill(B+m,B+lim,0);
NTT(A,1),NTT(B,1);
for(int i=0;i<lim;i++)A[i]=1ll*A[i]*B[i]%mod;
NTT(A,-1);
for(int i=0;i<k;i++)c[i]=A[i];
return c;
}
poly& operator *= (poly &a,const poly &b){
return a=a*b;
}
poly& operator += (poly &a,const poly &b){
int n=a.size(),m=b.size();
if(n<m)a.resize(m);
for(int i=0;i<m;i++)(a[i]+=b[i])%=mod;
return a;
}
poly operator + (const poly &a,const poly &b){ // poly addition
poly c(a);
return c+=b;
}
poly& operator -= (poly &a,const poly &b){
int n=a.size(),m=b.size();
if(n<m)a.resize(m);
for(int i=0;i<m;i++)(a[i]+=mod-b[i])%=mod;
return a;
}
poly operator - (const poly &a,const poly &b){ // poly subtraction
poly c(a);
return c-=b;
}
poly operator - (const poly &a){
return poly()-a;
}
poly& operator *= (poly &a,const int &b){
for(int &x:a)x=1ll*x*b%mod;
return a;
}
poly operator * (const poly &a,const int &b){
poly c(a);
return c*=b;
}
poly& operator /= (poly &a,const int &b){
return a*=qpow(b);
}
poly operator / (const poly &a,const int &b){
poly c(a);
return c/=b;
}
poly& operator %= (poly &a,const int &b){
if(a.size()>b)a.resize(b);
return a;
}
poly operator % (const poly &a,const int &b){
poly c(a);
return c%=b;
}
poly inv(poly a,int n=-1){ // A^-1 mod x^n
if(n==-1)n=a.size();
if(n==1)return poly(1,1);
int m=(n+1)/2;
auto b=inv(a%m,m);
init(n+m+m-2);
a.resize(lim),b.resize(lim);
NTT(a,1),NTT(b,1);
for(int i=0;i<lim;i++){
a[i]=(2+1ll*(mod-a[i])*b[i])%mod*b[i]%mod;
}
NTT(a,-1);
return a%n;
}
}
}
using namespace Poly::Public;
const int N=2e5+10;
int sid,n,m,p,a[N],b[N],c[N],d[N],e[N],f[N];
using vec=array<poly,2>;
using matrix=array<vec,2>;
#ifdef DEBUG
ostream& operator << (ostream &out,vec a){
out<<'[';
for(auto x:a)out<<x<<',';
return out<<']';
}
ostream& operator << (ostream &out,matrix a){
out<<'[';
for(auto x:a)out<<x<<',';
return out<<']';
}
#endif
matrix operator * (matrix a,matrix b){
int n=0;
for(int i:{0,1})for(int j:{0,1})for(int k:{0,1}){
n=max(n,(int)a[i][j].size()+(int)b[j][k].size()-1);
}
matrix c;
if(n<=50){
for(int i:{0,1})for(int j:{0,1})for(int k:{0,1}){
if(!a[i][j].empty()&&!b[j][k].empty())c[i][k]+=a[i][j]*b[j][k];
}
return c;
}
Poly::init(n),n=Poly::lim;
for(int i:{0,1})for(int j:{0,1}){
a[i][j].resize(n),b[i][j].resize(n),c[i][j].resize(n);
NTT(a[i][j],1),NTT(b[i][j],1);
}
for(int i:{0,1})for(int j:{0,1})for(int k:{0,1}){
for(int x=0;x<n;x++)c[i][k][x]=(c[i][k][x]+1ll*a[i][j][x]*b[j][k][x])%mod;
}
for(int i:{0,1})for(int j:{0,1}){
NTT(c[i][j],-1);
for(;!c[i][j].empty()&&!c[i][j].back();c[i][j].pop_back());
}
return c;
}
matrix mul(matrix a,matrix b){
matrix c;
for(int i:{0,1})for(int j:{0,1})for(int k:{0,1}){
if(!a[i][j].empty()&&!b[j][k].empty())c[i][k]+=a[i][j]*b[j][k];
}
return c;
}
vec solve(int l,int r){
if(l==r){
// debug("solve",l,r,vec{poly{b[l],1},poly{e[l]}});
return vec{poly{b[l],1},poly{e[l]}};
}
int mid=(l+r)>>1,n=0;
auto L=solve(l,mid),R=solve(mid+1,r);
for(int i:{0,1})for(int j:{0,1})if(!i||!j){
n=max(n,(int)L[i].size()+(int)R[j].size()-1);
}
// debug("solve",l,r);
Poly::init(n),n=Poly::lim;
vec t;
L[0].resize(n),NTT(L[0],1);
for(int i:{0,1}){
R[i].resize(n),t[i].resize(n);
NTT(R[i],1);
}
for(int i=0;i<n;i++){
t[0][i]=1ll*L[0][i]*R[0][i]%mod;
t[1][i]=1ll*L[0][i]*R[1][i]%mod;
}
NTT(t[0],-1),NTT(t[1],-1);
for(int i:{0,1}){
for(;!t[i].empty()&&!t[i].back();t[i].pop_back());
}
t[1]+=L[1];
// debug("solve",l,r,t);
return t;
}
struct node{
matrix F;
poly G[2][3];
poly calc(int cr){
return F[0][0]*poly{(mod-cr)%mod,1}+F[0][1];
}
void mul(poly g,int k){
Poly::init(G[0][0].size()+g.size()-1);
int n=Poly::lim;
g.resize(n),NTT(g,1);
for(int i:{0,1})for(int j:{0,1,2}){
G[i][j].resize(n),NTT(G[i][j],1);
for(int x=0;x<n;x++)G[i][j][x]=1ll*G[i][j][x]*g[x]%mod;
NTT(G[i][j],-1),G[i][j].resize(k);
}
}
};
void expand(poly &a,poly f,poly g,int m){
int n=a.size();
if(m<=n)return a%=m,void();
a=a*f%n*g%m;
}
const int K=300;
matrix gen(int i){
matrix cur;
cur[0][0]=poly{(mod-c[i])%mod,1};
cur[0][1]=poly{int(1ll*(mod-a[i])*d[i+1]%mod)};
cur[1][0]=poly{1};
return cur;
}
node divide(int l,int r){
int n=r-l+1;
if(r-l+1<=K){
node res;
function<matrix(int,int)>dfs=[&](int l,int r){
if(l==r)return gen(l);
int mid=(l+r)>>1;
return dfs(l,mid)*dfs(mid+1,r);
};
if(l<r)res.F=dfs(l,r-1);
else res.F[0][0]=res.F[1][1]=poly{1};
static int w[K][N];
for(int x:{0,1}){
for(int i=0;i<n;i++)fill(w[i]+l,w[i]+1+r,0);
w[0][x?r:l]=1;
for(int i=0;i+1<n;i++){
for(int j=l;j<=r;j++)w[i+1][j]=(w[i+1][j]+1ll*w[i][j]*c[j])%mod;
for(int j=l;j<r;j++)w[i+1][j+1]=(w[i+1][j+1]+1ll*w[i][j]*a[j])%mod;
for(int j=r;j>l;j--)w[i+1][j-1]=(w[i+1][j-1]+1ll*w[i][j]*d[j])%mod;
}
res.G[x][0].resize(n);
res.G[x][1].resize(n);
res.G[x][2].resize(n);
for(int i=0;i<n;i++){
res.G[x][0][i]=(res.G[x][0][i]+w[i][l])%mod;
res.G[x][1][i]=(res.G[x][1][i]+w[i][r])%mod;
for(int j=l;j<=r;j++){
res.G[x][2][i]=(res.G[x][2][i]+1ll*w[i][j]*f[j])%mod;
}
}
}
return res;
}
int mid=(l+r)>>1;
auto L=divide(l,mid-1),R=divide(mid+1,r);
auto fl=L.calc(c[mid-1]),fr=R.calc(c[r]);
reverse(all(fl)),reverse(all(fr));
auto ifl=inv(fl,n),ifr=inv(fr,n);
L.mul(fl,mid-l),R.mul(fr,r-mid);
L.mul(ifl,n),R.mul(ifr,n);
node res;
res.F=mul(L.F,gen(mid-1))*mul(gen(mid),R.F);
poly h=(poly{0,c[mid]}+
L.G[1][1]*poly{0,0,int(1ll*d[mid]*a[mid-1]%mod)}+
R.G[0][0]*poly{0,0,int(1ll*a[mid]*d[mid+1]%mod)})%n;
h=inv(poly{1}-h,n);
poly p[2],q[3];
p[0]=poly{0,a[mid-1]}*L.G[0][1]%n;
p[1]=poly{0,d[mid+1]}*R.G[1][0]%n;
q[0]=poly{0,d[mid]}*L.G[1][0]%n;
q[1]=poly{0,a[mid]}*R.G[0][1]%n;
q[2]=(poly{0,d[mid]}*L.G[1][2]+poly{0,a[mid]}*R.G[0][2]+poly{f[mid]})%n;
Poly::init(n+n-1);
int k=Poly::lim;
p[0].resize(k),p[1].resize(k),h.resize(k);
NTT(p[0],1),NTT(p[1],1),NTT(h,1);
for(int i=0;i<k;i++){
p[0][i]=1ll*p[0][i]*h[i]%mod;
p[1][i]=1ll*p[1][i]*h[i]%mod;
}
NTT(p[0],-1),NTT(p[1],-1);
p[0].resize(n),p[1].resize(n);
p[0].resize(k),p[1].resize(k);
q[0].resize(k),q[1].resize(k),q[2].resize(k);
NTT(p[0],1),NTT(p[1],1);
NTT(q[0],1),NTT(q[1],1),NTT(q[2],1);
for(int i:{0,1})for(int j:{0,1,2})res.G[i][j].resize(k);
for(int i=0;i<k;i++){
res.G[0][0][i]=1ll*p[0][i]*q[0][i]%mod;
res.G[0][1][i]=1ll*p[0][i]*q[1][i]%mod;
res.G[0][2][i]=1ll*p[0][i]*q[2][i]%mod;
res.G[1][0][i]=1ll*p[1][i]*q[0][i]%mod;
res.G[1][1][i]=1ll*p[1][i]*q[1][i]%mod;
res.G[1][2][i]=1ll*p[1][i]*q[2][i]%mod;
}
for(int i:{0,1})for(int j:{0,1,2}){
NTT(res.G[i][j],-1),res.G[i][j].resize(n);
}
res.G[0][0]+=L.G[0][0];
res.G[0][2]+=L.G[0][2];
res.G[1][1]+=R.G[1][1];
res.G[1][2]+=R.G[1][2];
return res;
}
int main(){
Poly::Init();
scanf("%d%d%d%d",&sid,&n,&m,&p);
for(int i=0;i<m;i++)scanf("%d",&a[i]);
for(int i=0;i<n;i++)scanf("%d",&b[i]);
for(int i=0;i<=m;i++)scanf("%d",&c[i]);
for(int i=1;i<=m;i++)scanf("%d",&d[i]);
for(int i=0;i<=n;i++)scanf("%d",&e[i]);
for(int i=0;i<=m;i++)scanf("%d",&f[i]);
poly h=solve(0,n)[1];
h.resize(n+1);
// debug(h);
node res=divide(0,m);
poly f=res.calc(c[m]),g=res.G[0][2];
reverse(all(f));
expand(g,f,inv(f,n+1),n+1);
// debug(f);
// for(int i:{0,1})for(int j:{0,1,2}){
// poly t;
// for(int x=0;x<res.G[i][j].size()&&x<10;x++)t.push_back(res.G[i][j][x]);
// debug(i,j,t);
// }
// debug(g,res.G[0][2],h,f);
int ans=0;
for(int i=0;i<=n;i++)ans=(ans+1ll*h[i]*g[i])%mod;
cout<<ans<<endl;
return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif
詳細信息
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 120ms
memory: 73008kb
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: 169ms
memory: 108856kb
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: 112ms
memory: 144552kb
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: 8304ms
memory: 251516kb
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: 8374ms
memory: 259284kb
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: 8325ms
memory: 250100kb
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: 8329ms
memory: 252180kb
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: 8424ms
memory: 263400kb
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: 7847ms
memory: 249648kb
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: 479ms
memory: 37932kb
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: 8338ms
memory: 251680kb
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: 495ms
memory: 225132kb
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: 7897ms
memory: 245116kb
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: 8293ms
memory: 251112kb
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: 8338ms
memory: 247468kb
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: 8337ms
memory: 256588kb
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: 8270ms
memory: 237220kb
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: 998ms
memory: 170016kb
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: 993ms
memory: 163888kb
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: 218ms
memory: 148344kb
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: 707ms
memory: 166012kb
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: 8387ms
memory: 256144kb
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: 6965ms
memory: 226920kb
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: 8346ms
memory: 252428kb
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: 8335ms
memory: 256572kb
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: 8341ms
memory: 247272kb
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: 8357ms
memory: 255636kb
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: 8353ms
memory: 257452kb
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: 8431ms
memory: 263448kb
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: 8373ms
memory: 255344kb
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: 8346ms
memory: 257068kb
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: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #32:
score: 0
Wrong Answer
time: 3583ms
memory: 212224kb
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:
756256154
result:
wrong answer 1st lines differ - expected: '304611769', found: '756256154'