QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#334197 | #6112. Village Planning | FISHER_ | AC ✓ | 593ms | 14500kb | C++20 | 4.3kb | 2024-02-21 14:03:29 | 2024-02-21 14:03:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353, inv2 = 499122177, rt = 3;
inline int Mod(int x) { return x + ((x >> 31) & mod); }
inline int add(int x, int y) { return Mod(x + y - mod); }
inline int sub(int x, int y) { return Mod(x - y); }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
int qpow(int a, int b) {
if (!b) return 1;
int t = qpow(a, b >> 1);
t = mul(t, t);
if (b & 1) return mul(t, a);
return t;
}
const int maxn = 100000;
namespace polynomial {
typedef vector<int> poly;
int rev[4 * maxn + 5];
inline void change(int len, int cnt) {
for (int i = 0; i < len; i++) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (cnt - 1));
}
void ntt(poly& a, int len, bool type) {
for (int i = 0; i < len; i++)
if (i < rev[i]) swap(a[i], a[rev[i]]);
for (int mid = 1; mid < len; mid <<= 1) {
int r = mid << 1;
int k = qpow(rt, (mod - 1) / r);
for (int i = 0; i < len; i += r) {
int w = 1;
for (int j = 0; j < mid; j++, w = mul(w, k)) {
int x = a[i + j], y = mul(w, a[i + mid + j]);
a[i + j] = add(x, y), a[i + mid + j] = sub(x, y);
}
}
}
if (type) {
reverse(a.begin() + 1, a.end());
int inv = qpow(len, mod - 2);
for (int i = 0; i < len; i++) a[i] = mul(a[i], inv);
}
}
poly polymul(poly a, poly b) {
int len = a.size() + b.size() - 1;
int l = 1, c = 0;
while (l < len) l <<= 1, c++;
a.resize(l), b.resize(l);
change(l, c);
ntt(a, l, 0), ntt(b, l, 0);
for (int i = 0; i < l; i++) a[i] = mul(a[i], b[i]);
ntt(a, l, 1);
a.resize(len);
return a;
}
poly polyinv(const poly& a, int len) {
if (len == 1) return {qpow(a[0], mod - 2)};
int l = 1, c = 0;
while (l < (len << 1)) l <<= 1, c++;
poly&& b = polyinv(a, (len + 1) >> 1);
b.resize(l);
poly f(l);
copy(a.begin(), a.begin() + len, f.begin());
change(l, c);
ntt(b, l, 0), ntt(f, l, 0);
for (int i = 0; i < l; i++) b[i] = mul(sub(2, mul(f[i], b[i])), b[i]);
ntt(b, l, 1);
b.resize(len);
return b;
}
poly polyint(const poly& a, int len) {
poly b(len);
for (int i = 1; i < len; i++) b[i] = mul(a[i - 1], qpow(i, mod - 2));
return b;
}
poly polyder(const poly& a, int len) {
poly b(len);
for (int i = 1; i < len; i++) b[i - 1] = mul(i, a[i]);
return b;
}
poly polyln(const poly& a, int len) {
int l = 1, c = 0;
while (l < (len << 1)) l <<= 1, c++;
poly&& f = polyder(a, len);
f.resize(l);
poly&& g = polyinv(a, len);
g.resize(l);
ntt(f, l, 0), ntt(g, l, 0);
change(l, c);
for (int i = 0; i < l; i++) f[i] = mul(f[i], g[i]);
ntt(f, l, 1);
return polyint(f, len);
}
poly polyexp(const poly& a, int len) {
if (len == 1) return {1};
int l = 1, c = 0;
while (l < (len << 1)) l <<= 1, c++;
poly&& b = polyexp(a, (len + 1) >> 1);
b.resize(l);
poly f(l);
copy(a.begin(), a.begin() + len, f.begin());
poly&& g = polyln(b, len);
g.resize(l);
change(l, c);
ntt(b, l, 0), ntt(f, l, 0), ntt(g, l, 0);
for (int i = 0; i < l; i++) b[i] = mul(add(1, sub(f[i], g[i])), b[i]);
ntt(b, l, 1);
b.resize(len);
return b;
}
} // namespace polynomial
using namespace polynomial;
int fac[maxn + 5], ifac[maxn + 5];
void init(int n) {
fac[0] = 1;
for (int i = 1; i <= n; i++) fac[i] = mul(fac[i - 1], i);
ifac[n] = qpow(fac[n], mod - 2);
for (int i = n - 1; ~i; i--) ifac[i] = mul(ifac[i + 1], i + 1);
}
inline int c2(int x) { return 1LL * x * (x - 1) / 2 % (mod - 1); }
int main() {
int n, k;
scanf("%d%d", &n, &k);
init(n);
int A[4] = {0, 0, 0, 0}, Ai[4] = {0, 0, 0, 0};
for (int i = 0; i <= k; i++) {
scanf("%d", &A[i]);
Ai[i] = qpow(A[i], mod - 2);
}
poly T(n + 1), T1(n + 1);
T[1] = T1[1] = 1;
for (int i = 2; i <= n; i++) {
T[i] = mul(mul(qpow(i, i - 2), qpow(A[1], c2(i))), ifac[i]);
T1[i] = mul(mul(T[i], qpow(Ai[2], c2(i))), i);
}
poly f(n + 1), g = polymul(T1, T1);
f[0] = 1;
for (int i = 1; i <= n; i++) f[i] = mod - T1[i];
f = polyln(f, n + 1);
poly cT(n + 1);
for (int i = 1; i <= n; i++) {
cT[i] = mul(mul(mod - add(f[i], add(T1[i], mul(g[i], inv2))), inv2), qpow(mul(A[2], Ai[0]), c2(i)));
T[i] = add(mul(T[i], qpow(Ai[0], c2(i))), cT[i]);
}
T = polyexp(T, n + 1);
for (int i = 2; i <= n; i++) printf("%d ", mul(T[i], mul(qpow(A[0], c2(i)), fac[i])));
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3804kb
input:
4 0 2
output:
2 8 64
result:
ok 3 number(s): "2 8 64"
Test #2:
score: 0
Accepted
time: 0ms
memory: 4012kb
input:
5 1 3 4
output:
7 327 96721 169832849
result:
ok 4 number(s): "7 327 96721 169832849"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
6 2 5 6 7
output:
11 1566 3000672 306031599 466869291
result:
ok 5 number(s): "11 1566 3000672 306031599 466869291"
Test #4:
score: 0
Accepted
time: 0ms
memory: 4072kb
input:
7 3 8 9 10 11
output:
17 5427 31856976 326774674 449014006 997476587
result:
ok 6 numbers
Test #5:
score: 0
Accepted
time: 580ms
memory: 14136kb
input:
100000 0 12345678
output:
12345678 644056040 211986440 366246078 129089719 221368866 283124263 92530495 602608963 591370683 990229283 164971576 676013258 861632667 266225306 38421683 734331905 954922439 924295443 581924621 641884577 953780417 395588140 569420628 269024687 923445182 812638938 221225256 415075963 833284693 182...
result:
ok 99999 numbers
Test #6:
score: 0
Accepted
time: 591ms
memory: 14344kb
input:
100000 0 1
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 99999 numbers
Test #7:
score: 0
Accepted
time: 576ms
memory: 14096kb
input:
100000 0 998244352
output:
998244352 998244352 1 1 998244352 998244352 1 1 998244352 998244352 1 1 998244352 998244352 1 1 998244352 998244352 1 1 998244352 998244352 1 1 998244352 998244352 1 1 998244352 998244352 1 1 998244352 998244352 1 1 998244352 998244352 1 1 998244352 998244352 1 1 998244352 998244352 1 1 998244352 99...
result:
ok 99999 numbers
Test #8:
score: 0
Accepted
time: 550ms
memory: 13496kb
input:
73812 0 3141592
output:
3141592 502595211 930804156 494129912 890907052 937804910 155794517 312377295 141669564 196035410 418956765 791193589 756093320 361837829 72344530 578759786 313970847 636643125 747705681 676578954 596656200 395491001 81642642 219037384 969715473 813221369 410880484 305249904 367704238 564789451 2855...
result:
ok 73811 numbers
Test #9:
score: 0
Accepted
time: 584ms
memory: 14176kb
input:
100000 1 1 1
output:
2 7 38 291 2932 36961 561948 10026505 205608536 774463267 589147789 829299664 243375906 66263611 965270387 154777431 601662699 929537049 893635200 219507261 392236640 775545378 714600599 56551872 187837583 189925757 50494333 611131417 258806070 413153890 109986030 618449809 731781234 408507333 28278...
result:
ok 99999 numbers
Test #10:
score: 0
Accepted
time: 589ms
memory: 14280kb
input:
100000 1 3127218 14172129
output:
17299347 544607138 680226212 305869647 912178269 916199911 125174848 307445424 256318706 16877857 462417641 298914440 279886537 287167270 564531297 111249855 460247698 805600287 58601732 199348757 45669640 366398551 149741463 906663559 976291245 366968697 90322856 347392377 225958266 867152353 84926...
result:
ok 99999 numbers
Test #11:
score: 0
Accepted
time: 588ms
memory: 14164kb
input:
100000 1 998244352 998244352
output:
998244351 998244346 38 291 998241421 998207392 561948 10026505 792635817 223781086 589147789 829299664 754868447 931980742 965270387 154777431 396581654 68707304 893635200 219507261 606007713 222698975 714600599 56551872 810406770 808318596 50494333 611131417 739438283 585090463 109986030 618449809 ...
result:
ok 99999 numbers
Test #12:
score: 0
Accepted
time: 576ms
memory: 14216kb
input:
100000 1 1 998244352
output:
0 998244348 2 211 998244033 998216494 84828 7784137 960946049 213292735 225093311 837100977 925933466 413576187 774455991 727906343 96771916 604528716 51075694 784377733 280737476 769195767 101561083 881507340 731348568 702337822 594671739 556715938 256133261 758927779 131639043 21463936 216796323 5...
result:
ok 99999 numbers
Test #13:
score: 0
Accepted
time: 592ms
memory: 14168kb
input:
99999 1 9 99
output:
108 2935683 905844104 884930131 610271296 167794683 874562044 144589021 654900997 739155189 156126745 259210590 364360898 474007353 202797476 105542 287700849 491427578 861300599 773784742 92662708 677626795 300989836 644734128 859127006 985588013 222572430 241496128 218066520 262003703 218365187 63...
result:
ok 99998 numbers
Test #14:
score: 0
Accepted
time: 588ms
memory: 14160kb
input:
100000 2 1 1 1
output:
2 8 57 608 8524 145800 2918123 66617234 706669081 384399752 501322809 82724887 450722832 428972217 181542374 652797702 609850214 874870984 765605342 147495034 696875380 556350159 263684494 785985697 927559849 434848582 197878990 406693583 792170563 800087590 373988208 3254512 227893387 739644336 696...
result:
ok 99999 numbers
Test #15:
score: 0
Accepted
time: 588ms
memory: 14152kb
input:
100000 2 998244352 998244352 998244352
output:
998244351 998244345 57 608 998235829 998098553 2918123 66617234 291575272 613844601 501322809 82724887 547521521 569272136 181542374 652797702 388394139 123373369 765605342 147495034 301368973 441894194 263684494 785985697 70684504 563395771 197878990 406693583 206073790 198156763 373988208 3254512 ...
result:
ok 99999 numbers
Test #16:
score: 0
Accepted
time: 585ms
memory: 14500kb
input:
100000 2 281937 171272 818181
output:
453209 512671672 278512868 972903940 963889823 375524158 428852795 714712820 193423966 165771254 162267306 204045783 876959521 473792164 304361203 460808773 98690013 488934388 435599530 450870701 792671254 1256206 718918641 426372134 650280375 627518981 362622544 779950240 420558947 804518581 306136...
result:
ok 99999 numbers
Test #17:
score: 0
Accepted
time: 585ms
memory: 14268kb
input:
100000 2 1 1 998244352
output:
2 6 25 148 444 2980 998007724 994444067 789019707 937713401 652696128 460709735 933939061 959266124 30637590 479943383 784813821 248526178 48920653 405125075 70154041 788942931 905407075 251620484 726975243 817166755 787087127 286858468 497248937 892303208 21757780 391004220 259168724 448745923 2696...
result:
ok 99999 numbers
Test #18:
score: 0
Accepted
time: 62ms
memory: 4540kb
input:
12345 2 12 34 56
output:
46 309944 696841896 34097 839911467 962123005 585561425 462868037 206865996 449479312 891836115 711985062 231298365 616854842 434054154 804312719 994410789 195833040 464775852 182224638 659030740 144745347 320691427 558457264 976986661 856936949 776831877 304530749 948340836 185453762 923617027 4324...
result:
ok 12344 numbers
Test #19:
score: 0
Accepted
time: 588ms
memory: 14072kb
input:
100000 3 1 1 1 1
output:
2 8 57 608 8524 145800 2918123 66617234 706669081 384399752 501322809 82724887 450722832 428972217 181542374 652797702 609850214 874870984 765605342 147495034 696875380 556350159 263684494 785985697 927559849 434848582 197878990 406693583 792170563 800087590 373988208 3254512 227893387 739644336 696...
result:
ok 99999 numbers
Test #20:
score: 0
Accepted
time: 588ms
memory: 14152kb
input:
100000 3 998244352 998244352 998244352 998244352
output:
998244351 998244345 57 608 998235829 998098553 2918123 66617234 291575272 613844601 501322809 82724887 547521521 569272136 181542374 652797702 388394139 123373369 765605342 147495034 301368973 441894194 263684494 785985697 70684504 563395771 197878990 406693583 206073790 198156763 373988208 3254512 ...
result:
ok 99999 numbers
Test #21:
score: 0
Accepted
time: 581ms
memory: 14128kb
input:
100000 3 1 1 1 998244352
output:
2 8 57 608 8524 145800 2918123 66617234 706669081 384399752 501322809 82724887 450722832 428972217 181542374 652797702 609850214 874870984 765605342 147495034 696875380 556350159 263684494 785985697 927559849 434848582 197878990 406693583 792170563 800087590 373988208 3254512 227893387 739644336 696...
result:
ok 99999 numbers
Test #22:
score: 0
Accepted
time: 588ms
memory: 14132kb
input:
100000 3 998244352 998244352 998244352 1
output:
998244351 998244345 57 608 998235829 998098553 2918123 66617234 291575272 613844601 501322809 82724887 547521521 569272136 181542374 652797702 388394139 123373369 765605342 147495034 301368973 441894194 263684494 785985697 70684504 563395771 197878990 406693583 206073790 198156763 373988208 3254512 ...
result:
ok 99999 numbers
Test #23:
score: 0
Accepted
time: 590ms
memory: 14104kb
input:
100000 3 39812 123981239 1290381 1283
output:
124021051 67339975 610940933 408695057 796120558 732352050 742684798 578755915 503423632 235119013 52640117 305547363 180205489 607460460 640936318 451441684 625594117 112271482 373199741 61881167 584975048 735163526 826958338 177994457 564490691 515336777 188170717 14714304 123547987 955921656 4472...
result:
ok 99999 numbers
Test #24:
score: 0
Accepted
time: 57ms
memory: 6396kb
input:
14141 3 14 1414 141414 14141414
output:
1428 945752601 419407338 158119279 300328028 268761179 344561129 762205485 365322155 382686822 562338952 664038583 58768435 150681229 319859602 215939428 298859979 361628698 332192869 242965952 140893160 904129517 921097456 654528502 906182473 473885111 536944482 344305087 540463307 642375040 802417...
result:
ok 14140 numbers
Test #25:
score: 0
Accepted
time: 580ms
memory: 14228kb
input:
100000 1 2137823 976866230
output:
979004053 685468134 789996596 45315913 734252866 114071945 227042021 607285911 6127041 313213017 262099069 41798701 310215621 339746433 773820973 760546987 20536197 958021016 391852714 130791407 69534615 385424002 927181151 954069501 620988719 894425458 857430548 138216414 59805573 582619921 3385707...
result:
ok 99999 numbers
Test #26:
score: 0
Accepted
time: 593ms
memory: 14180kb
input:
100000 2 333333333 664911020 3141592
output:
0 539258907 807446860 639440248 372497013 966644648 26618326 92668364 524085158 762416710 132072582 648218139 78338897 869553104 917456438 803122375 111752795 178884244 432005206 107545093 716582369 668087725 697533485 951887327 403870585 48142129 681202611 787661753 685854292 137355353 15775756 167...
result:
ok 99999 numbers
Test #27:
score: 0
Accepted
time: 585ms
memory: 14164kb
input:
100000 3 876543210 121701143 341287 234918
output:
0 489859077 963922989 839484222 354669793 734128410 360680805 298312130 493734073 937432342 397795686 348825298 101928832 887477366 876716304 876644325 217490999 828534006 772562207 907689566 966968848 34764183 351354852 557088404 975230095 531895571 637255401 909706248 962657325 937587650 813263917...
result:
ok 99999 numbers