QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#543866 | #3085. Do Use FFT | sherman2021 | AC ✓ | 1279ms | 70996kb | C++14 | 4.6kb | 2024-09-01 22:45:32 | 2024-09-01 22:45:32 |
Judging History
answer
#include <bits/stdc++.h>
#define int64 long long int
using namespace std;
inline int Read() {int res; return scanf("%d", &res), res; }
inline int64 Read64() {int64 res; return scanf("%lld", &res), res; }
const int N = 250000 + 5, Mod = 998244353;
const int G = 3, MAXN_NTT = 1 << 20 | 5, K = 20;
int ksm(int x, int y) {
(y < 0) && (y += Mod - 1);
int tmp = 1;
for(; y; y >>= 1) {
(y & 1) && (tmp = (int64)tmp * x % Mod);
x = (int64)x * x % Mod;
}
return tmp;
}
int w[MAXN_NTT];
inline void Init() {
w[1 << K] = ksm(G, (Mod - 1) >> (K + 2));
for (int i = K; i > 0; i -- ) w[1 << (i - 1)] = 1ll * w[1 << i] * w[1 << i] % Mod;
w[0] = 1;
for (int i = 1; i < 1 << K; i ++ ) w[i] = 1ll * w[i & -i] * w[i & (i - 1)] % Mod;
}
inline void DFT(int *a, int n) {
for (int m = n >> 1; m > 0; m >>= 1) {
for (int j = 0, l = 0; j < n; j += m << 1, l ++ ) {
for (int i = j; i < j + m; i ++ ) {
int p = a[i], q = 1ll * a[i + m] * w[l] % Mod;
(a[i] = p + q) >= Mod && (a[i] -= Mod), (a[i + m] = p - q) < 0 && (a[i + m] += Mod);
}
}
}
}
inline void IDFT(int *a, int n) {
for (int m = 1; m < n; m <<= 1) {
for (int j = 0, l = 0; j < n; j += m << 1, l ++ ) {
for (int i = j; i < j + m; i ++ ) {
int p = a[i], q = a[i + m];
(a[i] = p + q) >= Mod && (a[i] -= Mod), a[i + m] = (int64)(p - q + Mod) * w[l] % Mod;
}
}
}
for (int i = 1; i < n / 2; i ++ ) swap(a[i], a[n - i]);
int t = Mod - (Mod - 1) / n;
for (int i = 0; i < n; i ++ ) a[i] = (int64)a[i] * t % Mod;
}
inline void NTT(int *a, int n, int type) {if (type == 1) DFT(a, n); else IDFT(a, n);}
int a_mul[MAXN_NTT], b_mul[MAXN_NTT], c_mul[MAXN_NTT];
int Mul(int *a, int n, int *b, int m, int *c) {
int S;
for(S = 1; S <= n + m; S <<= 1);
for(int i = 0; i <= S; ++ i) a_mul[i] = b_mul[i] = 0;
for(int i = 0; i <= n; ++ i) a_mul[i] = a[i];
for(int i = 0; i <= m; ++ i) b_mul[i] = b[i];
NTT(a_mul, S, 1), NTT(b_mul, S, 1);
for(int i = 0; i <= S; ++ i) c_mul[i] = (int64)a_mul[i] * b_mul[i] % Mod;
NTT(c_mul, S, -1);
for(int i = 0; i <= n + m; ++ i) c[i] = c_mul[i];
return n + m;
}
int t_inv[MAXN_NTT], b_inv[MAXN_NTT];
void Inv(int *a, int *b, int n) { // mod x^n
b_inv[0] = ksm(a[0], Mod - 2);
int S = 1;
for(S = 1; S <= n; S <<= 1);
for(int T = 2; T <= S; T <<= 1) {
for(int i = 0; i < (T << 1); ++ i) t_inv[i] = 0;
for(int i = 0; i < T; ++ i) t_inv[i] = a[i];
NTT(t_inv, T << 1, 1), NTT(b_inv, T << 1, 1);
for(int i = 0; i < (T << 1); ++ i) b_inv[i] = (int64)(2ll - (int64)t_inv[i] * b_inv[i] % Mod + Mod) * b_inv[i] % Mod;
NTT(b_inv, T << 1, -1);
for(int i = T; i < (T << 1); ++ i) b_inv[i] = 0;
}
for(int i = 0; i < n; ++ i) b[i] = b_inv[i];
}
int t1_mult[MAXN_NTT], t2_mult[MAXN_NTT];
void Mult(int l, int r, int *var, int *c, int *g, int &n, int *h, int &m) {
if(l == r) {
h[0] = 1, h[1] = (Mod - var[l]), m = 1;
g[0] = c[l], n = 0;
return ;
}
int mid = (l + r) >> 1;
int ln, lm, rn, rm;
Mult(l, mid, var, c, g, ln, h, lm), Mult(mid + 1, r, var, c, g + mid - l + 1, rn, h + mid - l + 2, rm);
Mul(g, ln, h + mid - l + 2, rm, t1_mult), Mul(h, lm, g + mid - l + 1, rn, t2_mult);
Mul(h, lm, h + mid - l + 2, rm, h);
n = r - l, m = r - l + 1;
for(int i = 0; i <= n; ++ i) (g[i] = t1_mult[i] + t2_mult[i]) >= Mod && (g[i] -= Mod);
}
int t1_muls[MAXN_NTT], t2_muls[MAXN_NTT];
void Muls(int l, int r, int *sum, int *pro, int *b) {
if(l == r) {
printf("%lld ", (int64)((int64)sum[0] * b[l] + sum[1]) % Mod);
pro[0] = b[l], pro[1] = 1;
return ;
}
int mid = (l + r) >> 1;
Muls(l, mid, sum, pro, b);
for(int i = 0; i <= mid - l + 1; ++ i) t1_muls[i] = pro[i];
reverse(t1_muls, t1_muls + mid - l + 2);
int t3_muls[2 * (r - l + 1) + 5];
int gh = Mul(t1_muls, mid - l + 1, sum, r - l + 1, t3_muls);
for(int i = mid - l + 1; i <= gh; ++ i) t3_muls[i - (mid - l + 1)] = t3_muls[i];
for(int i = r - l + 2; i <= gh; ++ i) t3_muls[i] = 0;
Muls(mid + 1, r, t3_muls, pro + mid - l + 2, b);
Mul(pro, mid - l + 1, pro + mid - l + 2, r - mid, pro);
}
int n, a[MAXN_NTT], b[MAXN_NTT], c[MAXN_NTT];
int g[MAXN_NTT], h[MAXN_NTT];
int tt[MAXN_NTT];
int main() {
Init();
n = Read();
for(int i = 1; i <= n; ++ i) a[i] = Read();
for(int i = 1; i <= n; ++ i) b[i] = Read();
for(int i = 1; i <= n; ++ i) c[i] = Read();
int f1, f2;
Mult(1, n, a, c, g, f1, h, f2), Inv(h, h, n + 1), f1 = Mul(g, f1, h, n, g);
tt[0] = 1;
Muls(1, n, g, tt, b);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1212ms
memory: 53212kb
input:
250000 11956221 811436405 111283391 410252787 328579679 648193515 461380250 945461413 2468610 491078241 882989758 498321202 506978675 347568394 914487438 937090419 691517316 113670458 385303317 946859242 247139618 629416639 527506841 400920409 979063996 600868838 960126586 749289461 877729258 609309...
output:
341888287 691855678 287289300 463527368 32071971 752028808 473191742 681565447 303986352 783438121 893743623 379559400 693049973 321395317 418216248 844141652 102623073 164134039 587876880 354156358 529215226 986426326 76865240 711314848 315912634 584961957 179680993 87333628 567285487 480571825 482...
result:
ok single line: '341888287 691855678 287289300 ...5 25475363 690455300 209633366 '
Test #2:
score: 0
Accepted
time: 1216ms
memory: 52444kb
input:
250000 576772041 745547321 330079536 940364503 694563096 170508561 576140830 95144508 223789636 534142915 993858577 749058782 223247101 51665964 26566927 489176856 412042658 854057203 325602632 250594071 244220087 107237676 204228868 828196601 863226544 86372223 753177418 958664587 31978992 80858906...
output:
316617963 660218600 769733295 96996984 686860140 996126407 797789821 396080891 172612658 47962469 813736609 929404837 809390614 556634832 854178603 548098998 496895716 576449818 77075452 226996410 395609697 351224896 16031411 360486922 957508373 455563352 68047096 772819419 898749258 9770708 5052042...
result:
ok single line: '316617963 660218600 769733295 ...2 58688045 298304787 300979195 '
Test #3:
score: 0
Accepted
time: 1219ms
memory: 68516kb
input:
250000 271667840 111776117 37125046 83461416 537291029 539034873 792803963 969670464 612505501 214786923 663196412 832916080 518401508 817793672 723997021 699432332 711814289 733466268 886928644 879990078 738575594 841554232 655742750 874851939 452155722 240819332 382240078 657627452 754242885 53756...
output:
115205169 168654929 123450512 693827991 217345279 952372802 374394352 955666845 444621293 109702945 395860405 196857243 593731945 157597409 352941816 327011963 781266665 732575446 555511618 253520257 811313167 575085239 398822623 416281859 270643359 721421781 582268816 354761109 81381074 42502311 59...
result:
ok single line: '115205169 168654929 123450512 ... 617518503 684214725 618010376 '
Test #4:
score: 0
Accepted
time: 1243ms
memory: 52212kb
input:
250000 342452519 452729719 124540143 155480430 648851349 699468378 150898387 268943325 94495973 840628312 458590405 133031494 77313203 704617595 881912179 63709714 124704275 432823307 754118818 682209659 858464656 532530660 936921671 543365784 676136393 940113438 823668724 155689553 975371869 954683...
output:
844169023 929539680 287076878 9530893 907936597 458225076 809345317 830469550 718356039 96268848 482426541 641871291 579701988 902082870 135229457 610658460 178319291 864235270 734954542 746788402 384541266 260676708 759287650 207491345 804641528 979815015 707874249 320487322 401075726 83479950 3664...
result:
ok single line: '844169023 929539680 287076878 ... 450006818 386523490 297446795 '
Test #5:
score: 0
Accepted
time: 1268ms
memory: 52884kb
input:
250000 224556342 610022056 62616299 640912566 933220410 566877464 355808987 317081162 459811671 172573496 444190424 262936263 284525906 733055760 624845843 55091294 729827539 527592743 432818959 222486680 929432254 723492274 455038111 647072772 939321811 586684440 794733983 288813869 642190314 48275...
output:
542562435 11542874 148604544 785915352 623291850 367911563 73747437 991935462 663764823 284332968 561539749 453228205 679084246 842033452 981383048 940769973 644833329 868303238 808650257 747338872 54360461 442409140 817769176 120359617 151592964 723300452 282882796 296602243 774980857 816895486 144...
result:
ok single line: '542562435 11542874 148604544 7... 465099405 334661126 221663876 '
Test #6:
score: 0
Accepted
time: 1229ms
memory: 52496kb
input:
250000 974581818 900161300 463854450 768199379 430752394 895564076 927786375 58604160 297132854 660101604 98768304 858627377 959298958 392835847 98080329 102845058 791798385 359716360 818936216 926591205 535440929 548279967 370840244 982682004 653348761 588266935 948420641 395283523 294475996 167425...
output:
481855622 83267950 707499670 838830677 906231938 436781419 532485027 25339451 777242 852824728 950381938 621510520 732555790 513551674 660586908 634735419 207876401 731192868 49767299 88796151 245720586 373417231 397202048 312694641 850979007 289701450 382039058 240582831 464981277 103972244 7581753...
result:
ok single line: '481855622 83267950 707499670 8... 164562067 728847470 167727405 '
Test #7:
score: 0
Accepted
time: 1279ms
memory: 52968kb
input:
250000 743514512 553691437 789172590 643051379 812058576 434427870 488363523 825734394 891900659 720995400 860771659 827968636 98260629 692146213 59495676 407876025 427021688 709269447 516894111 536700694 323676463 872532707 9590217 323315749 515738333 627542126 638314099 870536618 496996597 4402557...
output:
387078887 457698908 568490847 194084099 706988873 616554508 751211124 935830128 524645866 415932178 100362090 468911630 301571050 221379488 711922272 20996670 475227202 470436647 879907319 690911568 535283746 713586364 836110732 770202976 200941676 592019588 895904916 941771067 232310670 145380796 2...
result:
ok single line: '387078887 457698908 568490847 ...4 101172100 779685953 48126219 '
Test #8:
score: 0
Accepted
time: 1248ms
memory: 70996kb
input:
250000 536872244 115488868 625764076 57265726 160234522 348705522 899586843 984810528 181480935 572558781 199759990 115658904 922868452 784894032 248508416 152326169 393584832 929546585 706592956 199308142 651938318 818706101 623060438 503212770 334890455 861378096 498091269 212619394 331407335 2927...
output:
885071773 674175609 640738827 642295030 2988703 251153143 128830181 868028525 171654622 687127315 631739042 806297692 7344321 153911408 395112921 462387871 483234444 888240426 443380158 946957700 688163912 287379718 67498042 299857422 80289954 531485983 561818340 723870951 176860538 439114337 514203...
result:
ok single line: '885071773 674175609 640738827 ... 315357963 500664390 196510763 '
Test #9:
score: 0
Accepted
time: 1231ms
memory: 65784kb
input:
250000 985078593 126708946 208874092 217950894 669909690 75905021 586534328 680609167 736292181 446572622 571443545 638411300 758215353 823867428 160177591 418925990 125745293 428340056 545539672 188354644 170668196 490685133 668603803 159790619 803244642 139751663 609519288 4072828 404826930 565456...
output:
366852830 124525222 402394072 847415370 265280883 890545236 685111991 484358559 523580837 477543179 500876532 245072997 669308673 325225584 442170020 710987664 70736961 110065597 679154620 318031934 100708180 215619544 889350610 905731230 245648456 977169959 546558357 530261065 624738982 292612431 3...
result:
ok single line: '366852830 124525222 402394072 ... 283516686 335381237 530223033 '
Test #10:
score: 0
Accepted
time: 1244ms
memory: 52096kb
input:
250000 787889192 913698867 563835287 126714324 263385941 832698473 226606812 711858552 205799210 674611782 384860656 727640395 882421991 839382660 520996677 932625144 60162168 608755744 827425742 913169349 409337587 282546605 418029502 35387109 972911962 888013183 262052601 361185718 743004141 85726...
output:
429893348 348763367 985492285 885737973 949748268 539952147 220905866 548609312 845483234 503604192 613300105 188709312 224932637 924497155 73826894 402165427 539535850 835179256 848458438 79101471 456643940 996604150 436441949 862688186 727254619 270968964 124883036 510198362 907963658 911326904 46...
result:
ok single line: '429893348 348763367 985492285 ... 481631666 571960738 765951078 '
Test #11:
score: 0
Accepted
time: 1237ms
memory: 52432kb
input:
250000 912204974 687803987 960197656 679921547 83608461 303998018 399850009 77411102 913966038 922855570 446682862 958196937 776690973 259342531 96654430 825815234 763781442 16164557 203346910 817751223 307066753 761701084 649387450 993476333 827949659 55323562 668786180 855125584 61544707 594252064...
output:
732356707 649592201 895632719 577598616 314886417 190652189 567925136 186792782 330902542 127945864 756351757 231345835 926050554 22450886 694685404 648580250 159426525 337126102 577971692 183894867 942076303 127914079 981351569 332687821 63608359 599681518 955679048 789754299 823045178 627226322 56...
result:
ok single line: '732356707 649592201 895632719 ...0 82751307 698001501 254280002 '
Test #12:
score: 0
Accepted
time: 1229ms
memory: 65976kb
input:
250000 618707829 840763512 667142944 367028042 909100543 953070727 769087733 264641496 418018301 250634362 401334628 944976438 483178284 879215394 990818001 117405747 137106598 499468835 712098345 728305014 31506013 900077699 388735646 404301271 159402668 914190701 120991672 23617693 207116855 75823...
output:
654518263 389684369 132614985 251756322 88709197 607101789 393383510 279534982 490340413 49078990 661655013 258122997 333044593 234793042 138440438 802883249 638868314 934459882 674461729 487062575 931208038 660062627 271308681 790615901 154759640 52494387 254179944 308224982 270272107 535833829 613...
result:
ok single line: '654518263 389684369 132614985 ... 836192349 339590595 566610773 '
Test #13:
score: 0
Accepted
time: 1226ms
memory: 53816kb
input:
250000 694211193 809143669 176927791 388378736 493124475 921580215 624074894 105792138 699803683 911757320 17705214 880486982 266960436 822908136 28360128 356311545 346038463 598116861 520653524 210508124 391988874 976271995 589583648 355015800 92789497 871837770 775707311 128222922 981679719 776188...
output:
425377917 250713470 965737209 303012913 641918317 104555766 204737295 315457449 827098585 861200105 824375114 451816420 155563044 562777781 198126380 428088286 80403326 156521623 470864980 31499770 779554795 210810478 340800215 224897436 989040011 892857713 453493081 74205955 540420014 853411315 588...
result:
ok single line: '425377917 250713470 965737209 ...9 160540220 77930712 886829783 '
Test #14:
score: 0
Accepted
time: 1236ms
memory: 52820kb
input:
250000 256915243 963749463 602503059 279995741 534719430 169012628 541660118 275678847 168297085 128209360 88747925 118521480 339090955 348986465 257059593 490433514 574267964 930611569 175924330 651675398 733114586 365168082 871470130 594441686 922712475 495673073 76058034 250811497 244825938 30482...
output:
585290383 647117724 611017166 448564031 638346419 412356755 603736208 441282811 773173319 16533626 953665036 841270214 834107468 605118679 141015631 130841251 257184061 211505204 878006609 961128419 259337077 367753965 321501277 775703245 741303222 638037134 849350502 611012740 835095578 125249796 8...
result:
ok single line: '585290383 647117724 611017166 ...8 86389836 770451770 126673945 '
Test #15:
score: 0
Accepted
time: 1247ms
memory: 68280kb
input:
250000 537002859 806201604 15632493 101660041 116950835 696037121 272680481 384953543 276949263 688191684 725217902 348669809 214156117 286916972 749954334 663535065 250993166 281548739 214119381 996827404 757484117 759023700 512711645 362588589 890889986 526967115 522132276 169284904 343957274 3515...
output:
61719988 342329479 180651820 668602472 878162107 850773516 928504197 950286919 875254998 316111743 790083713 394853050 29676022 613021047 614793374 463121050 909371011 125604451 562558609 697697444 21152368 995718524 171043979 539381001 134120542 631602349 490969736 671945501 385977969 888736950 665...
result:
ok single line: '61719988 342329479 180651820 6... 342173082 859141078 583943693 '
Test #16:
score: 0
Accepted
time: 1254ms
memory: 68532kb
input:
250000 295652770 458754015 659289251 449259498 157291747 529298945 145048456 315202335 530058389 421156362 966824594 82962009 137471050 622922729 892083350 223378028 207819072 801389108 293493544 159647632 705962712 392318554 656136907 746248002 720800244 884180882 882388620 79904765 966614234 94833...
output:
207185902 777581834 818852446 55606385 696719787 506464278 208351042 533483794 219408625 989711178 440012993 217598163 112753120 688782947 552797721 446266846 909749984 581011781 415303873 671746261 82383228 742727433 312949782 569148302 904498648 299864400 148983735 904700228 848986761 274998682 61...
result:
ok single line: '207185902 777581834 818852446 ...27 85639207 88068065 260985187 '
Test #17:
score: 0
Accepted
time: 1225ms
memory: 53060kb
input:
250000 680071507 93265407 980315124 834553033 248264657 61331850 792263724 489659103 111167849 736834047 177845316 695930945 139493976 391904786 483580827 217288882 159493683 137107274 641692177 360516393 273678298 110577635 929204717 771553819 61090065 838501075 451666195 742449933 306191766 347044...
output:
705305072 657614515 571489591 124607298 660804961 991094156 153590492 654851788 154523382 853247521 83723726 440585124 576406945 633695234 211240860 501502337 724769950 693623084 225621149 993404080 933014324 961926939 605610346 574172933 705758863 849868201 571737254 151994059 763117668 337684436 9...
result:
ok single line: '705305072 657614515 571489591 ...7 473740831 79840773 765534952 '
Test #18:
score: 0
Accepted
time: 1232ms
memory: 69392kb
input:
250000 358468434 679725211 541137543 874271660 93491102 698376584 413908935 298435528 982201716 313485211 848304041 158434584 41595006 952254725 187502483 10916066 454506025 831072993 985416139 987102241 322545216 575707439 838109317 165701436 538708028 939470545 245617413 711042311 195270164 712505...
output:
807711313 930789827 974475028 974307015 111189427 294427533 299605786 340802097 749934860 662430096 722957335 809750506 187307279 254584727 836971711 580585355 506486371 941253749 715973389 926940660 930553643 90139506 851265926 48279284 986917435 279372792 528426368 565225131 166266903 841956506 53...
result:
ok single line: '807711313 930789827 974475028 ...7 17887275 432583506 507925364 '
Test #19:
score: 0
Accepted
time: 1256ms
memory: 52984kb
input:
250000 559442037 325662459 650197279 884815130 495985327 645201086 971496919 63422405 355281445 719294437 916988477 134473714 190108350 163547310 179443099 770701750 711632141 325830915 476201291 443681736 108477325 13631202 694658230 294931956 971002206 563820239 906767898 753522054 545208198 22218...
output:
516716419 927472825 196865366 862513754 881299457 543585682 345902876 78793223 666642771 684088142 222889578 249388193 882193626 288581707 689025862 756039273 72817721 139167301 328048318 585982507 543199511 876830146 694240411 325933620 469045823 485821335 909472476 504463695 682782276 910422213 14...
result:
ok single line: '516716419 927472825 196865366 ... 371895039 587523367 151679717 '
Test #20:
score: 0
Accepted
time: 1235ms
memory: 53216kb
input:
250000 951394674 447021549 704132290 846258838 511047161 289442125 891241193 720415653 853391207 477986680 929445518 707947297 93305993 182670136 54303483 53321431 553653906 586684431 262474230 831775716 595161654 7237063 694518091 875124533 81162292 642211181 450168454 17944833 93650579 806016379 9...
output:
551497902 449592188 442624536 904991361 198241116 537013318 23961280 794507384 152343607 434600930 748938797 587514849 390725672 141657946 483123123 48898412 304618279 232583248 448719431 919545907 912598507 315372758 840894193 144459158 455856039 81955612 368380567 468456091 364604688 564519067 487...
result:
ok single line: '551497902 449592188 442624536 ...1 980980982 150386605 72736498 '