QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#88971 | #4552. 如何优雅地求和 | RainAir | 100 ✓ | 12ms | 8180kb | C++23 | 3.0kb | 2023-03-18 03:08:54 | 2023-03-18 03:08:57 |
Judging History
answer
#include<bits/stdc++.h>
#define fi first
#define se second
#define U unsigned
#define P std::pair<int,int>
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const int MAXN = 5e5 + 5;
const int ha = 998244353;
const int G = 3;
const int Gn = 332748118;
inline int qpow(int a,int n=ha-2){
int res = 1;
while(n){
if(n & 1) res = 1ll*res*a%ha;
a = 1ll*a*a%ha;
n >>= 1;
}
return res;
}
inline void add(int &x,int y){
(x += y);while(x >= ha) x -= ha;
}
struct Poly{
std::vector<int> x;
inline int deg(){return (int)x.size()-1;}
inline void ext(int n){x.resize(n+1);}
inline int& operator [] (const int &p){return x[p];}
};
Poly operator + (Poly a,Poly b){
if(a.deg() < b.deg()) std::swap(a,b);
FOR(i,0,b.deg()) add(a[i],b[i]);
return a;
}
Poly operator - (Poly a,Poly b){
bool flag = 0;
if(a.deg() < b.deg()) std::swap(a,b),flag = 1;
FOR(i,0,b.deg()) add(a[i],ha-b[i]);
if(flag) FOR(i,0,a.deg()) a[i] = (ha-a[i])%ha;
return a;
}
int N,r[MAXN<<2];
int W[MAXN],Wn[MAXN];
inline void prework22(){
FOR(i,0,20){
W[i] = qpow(G,(ha-1)/(1<<(i+1)));
Wn[i] = qpow(Gn,(ha-1)/(1<<(i+1)));
}
}
inline void init(int n){
int len = 0;N = 1;while(N <= n) N <<= 1,len++;
FOR(i,0,N-1) r[i] = (r[i>>1]>>1)|((i&1)<<(len-1));
}
inline void NTT(Poly &A,int opt){
A.ext(N);if(!W[0]) prework22();
FOR(i,0,N-1) if(i < r[i]) std::swap(A[i],A[r[i]]);
for(int mid = 1,cnt = 0;mid < N;mid <<= 1,cnt++){
int W = opt==-1?(::Wn[cnt]):(::W[cnt]);
for(int i = 0;i < N;i += (mid<<1)){
for(int w=1,j = 0;j < mid;j++,w = 1ll*w*W%ha){
int x = A[i+j],y = 1ll*w*A[i+mid+j]%ha;
A[i+j] = (x+y)%ha;A[i+mid+j] = (x+ha-y)%ha;
}
}
}
if(opt == -1){
int inv = qpow(N);
FOR(i,0,N-1) A[i] = 1ll*A[i]*inv%ha;
}
}
Poly operator * (Poly A,Poly B){
int len = A.deg()+B.deg();init(len);
NTT(A,1);NTT(B,1);
FOR(i,0,N-1) A[i] = 1ll*A[i]*B[i]%ha;
NTT(A,-1);A.ext(len);
return A;
}
int n,m,x;
int a[MAXN];
int fac[MAXN],inv[MAXN];
inline void prework(){
fac[0] = 1;FOR(i,1,MAXN-1) fac[i] = 1ll*fac[i-1]*i%ha;
inv[MAXN-1] = qpow(fac[MAXN-1]);
ROF(i,MAXN-2,0) inv[i] = 1ll*inv[i+1]*(i+1)%ha;
}
int main(){
prework();
scanf("%d%d%d",&n,&m,&x);
FOR(i,0,m) scanf("%d",a+i);
Poly A,B;A.ext(m);B.ext(m);
FOR(i,0,m){
A[i] = 1ll*a[i]*inv[i]%ha;
B[i] = inv[i];if(i&1) B[i] = ha-B[i];
}
A = A*B;
int tp = n,now = 1;
int ans = 0,p = 1;
FOR(i,0,m){
(ans += 1ll*A[i]*p%ha*now%ha) %= ha;
p = 1ll*p*x%ha;
if(tp > 0) now = 1ll*now*tp%ha;
tp--;
}
printf("%d\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 8ms
memory: 7464kb
input:
100 100 133860013 794216030 545630468 535373340 681004830 753155468 2680450 105693375 518005489 897014100 500942829 997151601 667007464 91736015 433225102 925017061 85974855 500030009 363988940 173653425 968669105 289184566 517436890 756486993 235255223 69278880 107265295 446355639 892379811 1361846...
output:
865916449
result:
ok 1 number(s): "865916449"
Test #2:
score: 5
Accepted
time: 8ms
memory: 7560kb
input:
1000 1000 379317338 460923986 466041450 290967353 501524928 718239371 450092437 427711243 677445812 696620161 681064347 812763849 419590567 546691054 492234099 219271744 511342569 97760050 207346856 604091175 555559126 624742734 206429806 443776004 376878852 784982516 83274156 562982864 639453584 46...
output:
569471924
result:
ok 1 number(s): "569471924"
Test #3:
score: 5
Accepted
time: 9ms
memory: 7516kb
input:
10000 90 553134058 795889349 258493606 94911677 152744143 885766671 69487209 29458125 599019659 63525831 810219747 235128336 574741720 292250567 979032093 825318040 535403322 653684191 418165265 441554942 118132526 965057080 393835787 667654424 117852644 53523894 595342039 255107077 354301570 945160...
output:
340512707
result:
ok 1 number(s): "340512707"
Test #4:
score: 5
Accepted
time: 8ms
memory: 7416kb
input:
90909 95 76191496 796190005 336013330 313281818 136122228 910767049 188622961 231812373 491964897 464583289 619007453 312511038 200466464 978838700 824986489 540609888 778760819 762248930 627440917 134081709 760402976 366755668 158413671 417643922 104148038 830279350 51055965 274012172 658446902 719...
output:
829201124
result:
ok 1 number(s): "829201124"
Test #5:
score: 5
Accepted
time: 1ms
memory: 7516kb
input:
909090 97 37348550 576471799 465023447 458616093 80158438 44424278 977371148 668982991 543389921 810652672 170851218 142499489 234484449 683697511 485750136 673161788 325731944 494775339 532998562 479502525 896103030 809765952 716790561 187573762 627968446 151694545 407166464 42314681 714665873 9795...
output:
407880684
result:
ok 1 number(s): "407880684"
Test #6:
score: 5
Accepted
time: 8ms
memory: 7588kb
input:
999999787 1 1 962552531 143301326
output:
234791071
result:
ok 1 number(s): "234791071"
Test #7:
score: 5
Accepted
time: 5ms
memory: 7508kb
input:
999999944 2 773504401 0 1 4
output:
278084784
result:
ok 1 number(s): "278084784"
Test #8:
score: 5
Accepted
time: 1ms
memory: 7580kb
input:
999999135 2 465747000 0 0 2
output:
180751969
result:
ok 1 number(s): "180751969"
Test #9:
score: 5
Accepted
time: 9ms
memory: 7508kb
input:
1000000000 3 21216356 111247080 796755814 583439797 842526695
output:
406964762
result:
ok 1 number(s): "406964762"
Test #10:
score: 5
Accepted
time: 8ms
memory: 7460kb
input:
993999563 6 665637445 922376106 627256748 953905014 681550999 548948411 265575769 328660250
output:
682043189
result:
ok 1 number(s): "682043189"
Test #11:
score: 5
Accepted
time: 8ms
memory: 7512kb
input:
994999897 9 922816200 828957950 382766786 455589991 210276899 220065322 664274186 428648517 257488462 865910676 251386572
output:
673739493
result:
ok 1 number(s): "673739493"
Test #12:
score: 5
Accepted
time: 1ms
memory: 7404kb
input:
908115435 33 799549151 453603176 62646701 890881822 396931885 70416206 673207832 857754112 802010882 460326250 560139719 98491302 835079926 472749530 57037949 229925163 38474573 21507548 137798115 474868202 792830110 643994954 239044587 734781970 121637498 298208316 92180032 975930165 538485175 7107...
output:
905808768
result:
ok 1 number(s): "905808768"
Test #13:
score: 5
Accepted
time: 1ms
memory: 7472kb
input:
989936365 66 412064955 595980804 271574715 412074517 58062701 831714434 359570877 742147685 155224669 265613885 972072848 42704300 136126491 111626610 517572502 928956602 604626622 756617089 665494219 726264120 903830463 606679310 703949933 293076343 168209203 180950660 474206788 183342273 869837383...
output:
230850567
result:
ok 1 number(s): "230850567"
Test #14:
score: 5
Accepted
time: 4ms
memory: 7460kb
input:
970601872 99 390252088 572320165 607178150 46924041 19471981 112981292 474320918 982440653 245751152 508100063 554542767 45770878 118904034 32230991 452469915 282662996 801239911 876383213 778367560 895216325 334399489 994670213 236933205 236828053 541634589 420615707 7994207 829579559 506082179 266...
output:
965811382
result:
ok 1 number(s): "965811382"
Test #15:
score: 5
Accepted
time: 8ms
memory: 7544kb
input:
917655104 1000 163840370 352803054 832726299 260369539 674429993 435887494 355313012 386218137 702110 447298521 232388868 859813990 381756986 449875391 951572596 398333110 159059177 132977194 479357043 168012289 578138993 393431252 260985856 436532189 818326240 873134815 24586604 95320269 162471606 ...
output:
57254422
result:
ok 1 number(s): "57254422"
Test #16:
score: 5
Accepted
time: 9ms
memory: 7512kb
input:
975664260 2000 245386427 977847748 787405635 132906317 188218658 105185168 546915055 903559565 535054072 66735269 14145011 265944620 95295369 6870729 384079925 484479806 326422815 208099523 885109185 200681946 653739240 253494620 512397440 732917130 459625672 348645863 31129514 397328802 904655340 4...
output:
469000978
result:
ok 1 number(s): "469000978"
Test #17:
score: 5
Accepted
time: 10ms
memory: 7588kb
input:
920546466 4000 947740772 666495508 334163627 268420669 740051791 379160751 645274460 64979784 581413242 967035695 18056222 209272995 164751974 564590654 332491059 665770280 623844038 533456666 966426211 103393463 61570520 163962785 376646945 434544899 811168427 314454434 889367016 623941355 56521790...
output:
875136086
result:
ok 1 number(s): "875136086"
Test #18:
score: 5
Accepted
time: 7ms
memory: 7692kb
input:
985661745 8000 471619683 940831080 428991947 403368000 52357964 478374085 927701580 169923691 334930807 970221025 591659100 258099967 715619468 502586108 83803715 830966705 440086938 125330363 761191120 556779903 484653833 126638033 26475019 461211776 919913639 773405080 471222411 441429297 70016502...
output:
41366997
result:
ok 1 number(s): "41366997"
Test #19:
score: 5
Accepted
time: 7ms
memory: 7916kb
input:
942855705 12000 620856510 870226084 744842350 733038341 71326354 324783711 946249089 47913889 552377847 956182823 909173925 496221724 748662643 869918222 15097898 324783182 940101151 351130713 885540354 956927798 65392299 702092339 696611786 157660746 150535554 259370269 526688412 342932504 91808938...
output:
565201163
result:
ok 1 number(s): "565201163"
Test #20:
score: 5
Accepted
time: 12ms
memory: 8180kb
input:
962657420 20000 707529234 473540237 731236314 764037756 189576043 863113652 705762029 638342941 99272398 57159476 462183032 99431513 476596471 42953200 381023313 442265077 366510437 178310211 415208780 736316039 673552574 438809737 310201283 938886298 331712259 698862232 12012042 121584953 987945580...
output:
652536354
result:
ok 1 number(s): "652536354"
Extra Test:
score: 0
Extra Test Passed