QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#9707 | #618. 多项式乘法 | RainAir# | 100 ✓ | 823ms | 39284kb | C++11 | 2.0kb | 2021-04-09 13:32:46 | 2021-12-19 11:40:04 |
Judging History
answer
#include <bits/stdc++.h>
#define fi first
#define se second
#define DB double
#define U unsigned
#define P std::pair
#define LL long long
#define LD long double
#define pb emplace_back
#define MP std::make_pair
#define SZ(x) ((int)x.size())
#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 = (1<<21) + 5;
const int ha = 998244353;
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;
}
struct Poly{
std::vector<int> x;
inline int deg(){return SZ(x)-1;}
inline void ext(const int &n){x.resize(n+1);}
inline int& operator [] (const int &n){return x[n];}
};
int r[MAXN],N;
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-1);FOR(i,0,N-1) if(i < r[i]) std::swap(A[i],A[r[i]]);
for(int mid = 1;mid < N;mid <<= 1){
int W = qpow(3,(ha-1)/(mid<<1));
for(int i = 0;i < N;i += (mid<<1)){
for(int j = 0,w = 1;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){
std::reverse(A.x.begin()+1,A.x.end());
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 main(){
int n,m;Poly A,B;scanf("%d%d",&n,&m);
A.ext(n);B.ext(m);
FOR(i,0,n) scanf("%d",&A[i]);
FOR(i,0,m) scanf("%d",&B[i]);
A = A*B;
FOR(i,0,n+m) printf("%d ",A[i]);puts("");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 20
Accepted
time: 2ms
memory: 3660kb
input:
96 96 600395131 184265451 942971382 534262851 830366882 542271170 294355449 501371170 797809599 964826049 276651245 375755165 662619442 941920605 328216963 507795473 460271147 874920847 818231910 156789488 590591583 732194508 793983630 93566697 836155866 305319153 432040686 621119061 835023373 571381805 907090013 2182462 302915289 855760137 453034423 194501808 602679162 754637041 43020929 280523649 563297193 586403321 953313978 846966649 939322157 224782218 423578586 553034359 236753930 97579416...
output:
683858396 5532883 499734624 910262414 221004044 924081841 392466229 64190174 260661815 939986106 283456690 260629512 990528995 704246427 991946815 236857583 903415172 900324859 938555797 225258152 874945420 516870315 74759441 769850097 353889928 300397164 63689540 115003940 872945378 407694641 918439552 365361049 166223369 494640009 11277932 19286675 116841528 442270318 666069367 759723249 544983364 151656303 570763112 156623415 892797472 901742208 792908145 94793151 409382727 887377891 30446689...
result:
ok 193 numbers
Test #2:
score: 20
Accepted
time: 7ms
memory: 3772kb
input:
4992 4994 471194390 313639917 705341086 119536186 430124603 244978845 185588341 13731324 707132801 88167972 927324568 846658454 523684029 5133605 767200778 502476309 539772401 778154025 266136872 183516351 260704325 49303370 475056182 928574546 740424153 277920667 708439854 746983628 839491869 53579512 244429021 50734540 136957850 76303465 579487379 368990885 163226387 580415257 208768433 19113590 223054273 551672113 124853857 40273596 563383965 193659125 125299959 606009066 177398857 298766403 ...
output:
700935456 677302967 772159864 479386810 109686665 263919131 29567167 960045078 636326916 585682137 409426717 14510019 441964472 92801447 551536199 216995135 59736203 790078879 55883568 796138076 265361608 66124731 150347029 93682849 205256362 672081205 86396898 573029352 541084997 293480941 905180715 745063618 450720923 554964923 176281926 539834324 212383399 210133291 327424853 419969778 763399537 976096781 402502902 736010903 892302431 403156090 192609087 559600298 556887890 656334360 97153151...
result:
ok 9987 numbers
Test #3:
score: 20
Accepted
time: 21ms
memory: 4428kb
input:
29995 29992 417238081 53580806 733071257 224121793 786137422 127072245 129083351 988357079 246853229 150935424 596994106 975796660 838029970 619117898 328485797 948485083 574261409 79312345 596346086 489787404 929520168 515647000 211731260 50868568 811515357 428215135 498099163 644485329 802849075 323480593 82977609 981158224 146168797 843709970 940251244 748340642 715098449 135717736 386164511 936195593 287388374 780056143 263853402 955329298 295993331 384883174 985705100 42684143 46671610 3591...
output:
115270920 49832720 758693293 745763567 322999821 510579248 697424729 850661201 678364508 817667211 668544763 136619207 562899653 692811546 351397117 768369036 573254435 891143982 717302438 707939747 41743610 540709722 240732780 931265491 38731999 642520590 630812534 632188732 342954490 225414102 836275879 245409154 261148460 74499071 726053513 256301472 280872033 760295493 655322079 838128260 644215631 844006112 234351296 236754275 919988249 398607994 910292849 705948390 120172437 901283825 2778...
result:
ok 59988 numbers
Test #4:
score: 20
Accepted
time: 85ms
memory: 7212kb
input:
100000 99993 812398607 947396010 797321381 883949986 56052416 586258761 193247973 611124334 773505112 142179482 565466227 140875825 79890768 893500101 553768089 648879319 480419657 915530184 799329430 494818755 793895824 851865180 459534006 259473419 610037701 472768430 868914058 887444584 588850309 931042551 140500440 113474012 799450889 774662643 30955294 500108316 30652117 259096565 434687860 315020281 896443850 55195632 961583298 802194511 161293453 553381027 902400419 795643835 692301037 85...
output:
821875273 646409297 701893040 744951544 891720486 338002304 134405948 686576985 653633849 704180950 763960458 160339533 773107048 630019221 467173934 675237413 824356289 394352126 870024535 473719536 246319541 372709664 656104889 677100818 890131281 374587639 160832628 144239351 450760970 646488586 937498881 316343487 449678851 341495560 8622941 832517340 141757002 419455265 90093720 800532734 552603236 970133392 502041503 847074169 957032987 94583864 147091044 758523971 474285106 684011302 6091...
result:
ok 199994 numbers
Test #5:
score: 20
Accepted
time: 823ms
memory: 39284kb
input:
999993 999994 388529697 811245378 165909114 295553883 667981275 78502012 400874009 139394758 249494489 4636487 997712665 259780805 431039016 716944209 709300152 356513646 823185021 699568300 650937921 859190797 899514799 785648601 933470757 627225124 349752104 471458923 456404256 48134357 315599086 833579801 571765596 992347138 98921603 132574566 124250140 864032331 752503099 921369464 868713168 689411883 275126498 61746579 230876576 589241003 500341687 478442921 800494882 561661108 319422304 38...
output:
199012842 735467570 660520906 870291510 102406003 509914017 591503608 692425397 149848591 232605296 411728228 285507919 90090498 682749099 507720817 425946949 937188332 619041823 738654334 153862895 272311969 793838225 260785140 350903642 151151058 631242104 304026658 123734332 23714740 438936743 779982052 79220693 49998320 581971246 415648559 189033611 410979525 459419417 889437666 519164001 2246430 370565883 123550553 586086725 817404691 154179901 554931811 369292823 271484314 110747055 115604...
result:
ok 1999988 numbers