QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#305937#6112. Village PlanningckisekiAC ✓347ms13172kbC++206.3kb2024-01-16 06:16:022024-01-16 06:16:02

Judging History

你现在查看的是最新测评结果

  • [2024-01-16 06:16:02]
  • 评测
  • 测评结果:AC
  • 用时:347ms
  • 内存:13172kb
  • [2024-01-16 06:16:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

namespace {

const int mod = 998244353;
const int G = 3;
const int maxn = 1 << 20;

int modadd(int a, int b) {
    return a + b >= mod ? a + b - mod : a + b;
}
int modsub(int a, int b) {
    return a - b < 0 ? a - b + mod : a - b;
}
int modmul(int64_t a, int64_t b) {
    return static_cast<int>(a * b % mod);
}
int modpow(int e, int64_t p) {
    int r = 1;
    while (p) {
        if (p & 1) r = modmul(r, e);
        e = modmul(e, e);
        p >>= 1;
    }
    return r;
}
int modinv(int x) {
    return modpow(x, mod - 2);
}

struct NTT {
    static_assert (maxn == (maxn & -maxn));
    int roots[maxn];
    NTT() {
        int r = modpow(G, (mod - 1) / maxn);
        for (int i = maxn >> 1; i; i >>= 1) {
            roots[i] = 1;
            for (int j = 1; j < i; j++)
                roots[i + j] = modmul(roots[i + j - 1], r);
            r = modmul(r, r);
        }
    }
    void operator()(int F[], int n, bool inv = false) {
        for (int i = 0, j = 0; i < n; i++) {
            if (i < j) swap(F[i], F[j]);
            for (int k = n >> 1; (j ^= k) < k; k >>= 1)
                ;
        }
        for (int s = 1; s < n; s *= 2) {
            for (int i = 0; i < n; i += s * 2) {
                for (int j = 0; j < s; j++) {
                    int a = F[i + j];
                    int b = modmul(F[i + j + s], roots[s + j]);
                    F[i + j] = modadd(a, b);
                    F[i + j + s] = modsub(a, b);
                }
            }
        }
        if (inv) {
            int invn = modinv(n);
            for (int i = 0; i < n; i++)
                F[i] = modmul(F[i], invn);
            reverse(F + 1, F + n);
        }
    }
};

NTT ntt;

using V = vector<int>;
#define fi(l, r) for (int i = int(l); i < int(r); ++i)
struct Poly : V {
    static uint32_t n2k(uint32_t n) {
        if (n <= 1) return 1;
        return 1u << (32 - __builtin_clz(n - 1));
    }
    explicit Poly(int n = 1) : V(n) {}
    Poly (const V &v) : V(v) {}
    Poly(const Poly &p, size_t n) : V(n) {
        copy_n(p.data(), min(p.size(), n), data());
    }
    Poly &isz(int sz) { return resize(sz), *this; }
    Poly &iadd(const Poly &rhs) {
        fi(0, size()) (*this)[i] = modadd((*this)[i], rhs[i]);
        return *this;
    }
    Poly &imul(int k) {
        fi(0, size()) (*this)[i] = modmul((*this)[i], k);
        return *this;
    }

    Poly Mul(const Poly &rhs) const {
        const int sz = n2k(size() + rhs.size() - 1);
        Poly X(*this, sz), Y(rhs, sz);
        ntt(X.data(), sz), ntt(Y.data(), sz);
        fi(0, sz) X[i] = modmul(X[i], Y[i]);
        ntt(X.data(), sz, true);
        return X.isz(size() + rhs.size() - 1);
    }
    Poly Inv() const {
        if (size() == 1) return V{modinv(*begin())};
        const int sz = n2k(size() * 2);
        Poly X = Poly(*this, (size() + 1) / 2).Inv().isz(sz),
             Y(*this, sz);
        ntt(X.data(), sz);
        ntt(Y.data(), sz);
        fi(0, sz) X[i] = modmul(X[i], modsub(2, modmul(X[i], Y[i])));
        ntt(X.data(), sz, true);
        return X.isz(size());
    }
    Poly Dx() const {
        Poly ret(size() - 1);
        fi(0, ret.size()) ret[i] = modmul(i + 1, (*this)[i + 1]);
        return ret.isz(max<int>(1, ret.size()));
    }
    Poly Sx() const {
        Poly ret(size() + 1);
        fi(0, size()) ret[i + 1] = modmul(modinv(i + 1), (*this)[i]);
        // TODO
        return ret;
    }


    Poly Ln() const {
        return Dx().Mul(Inv()).Sx().isz(size());
    }
    Poly Exp() const {
        if (size() == 1) return V{1};
        Poly X = Poly(*this, (size() + 1) / 2).Exp().isz(size());
        Poly Y = X.Ln();
        Y[0] = mod - 1;
        fi(0, size()) Y[i] = modsub((*this)[i], Y[i]);
        return X.Mul(Y).isz(size());
    }
};

}

void PRINT(Poly &p) {
    cerr << "PRINT =======" << endl;
    for (int i = 0; i < p.size(); i++) {
        cerr << p[i] << ", ";
    }
    cerr << endl;
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int n, k;
    cin >> n >> k;
    int A[10];
    for (int i = 0; i <= k; i++)
        cin >> A[i];
    if (k == 3) {
        k = 2;
    }

    if (k == 0) {
        for (int i = 2; i <= n; i++) {
            cout << modpow(A[0], 1LL*i*(i-1)/2) << (i==n ? '\n' : ' ');
        }
        return 0;
    }

    A[1] = modmul(A[1], modinv(A[0]));
    A[2] = modmul(A[2], modinv(A[0]));

    Poly F(n + 1);
    // PRINT(F);
    for (int i = 1; i <= n; i++) {
        F[i] = modmul(modpow(i, max(0, i - 2)), modpow(A[1], 1LL*i*(i-1)/2));
    }
    // cerr << "here" << endl;

    vector<int> fac(n + 1), ifac(n + 1);
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
        fac[i] = modmul(fac[i-1], i);
    for (int i = 0; i <= n; i++)
        ifac[i] = modinv(fac[i]);

    if (k == 2) {
        Poly H(n + 1);
        {
            const int rt = modmul(A[1], modinv(A[2]));
            for (int i = 1; i <= n; i++) {
                H[i] = modmul(modpow(i, max(0, i - 1)), modpow(rt, 1LL*i*(i-1)/2));
            }
        }
        for (int i = 1; i <= n; i++) {
            H[i] = modmul(H[i], ifac[i]);
        }

        Poly G = H;
        for (int i = 1; i <= n; i++) {
            G[i] = modsub(0, G[i]);
        }
        G[0] = 1;
        
        G = G.Ln();

        for (int i = 1; i <= n; i++)
            G[i] = modsub(0, G[i]);

        Poly H2 = H.Mul(H).imul(modinv(2));

        for (int i = 0; i <= n; i++) {
            G[i] = modsub(G[i], modadd(H[i], H2[i]));
            G[i] = modmul(G[i], modpow(A[2], 1LL*i*(i-1)/2));
        }

        for (int i = 0; i <= n; i++)
            G[i] = modmul(G[i], fac[i]);

        int inv2 = modinv(2);
        for (int i = 0; i <= n; i++)
            G[i] = modmul(G[i], inv2);

        for (int i = 0; i <= n; i++) {
            F[i] = modadd(F[i], G[i]);
        }
    }

    for (int i = 0; i <= n; i++) {
        F[i] = modmul(F[i], ifac[i]);
    }

    // PRINT(F);
    F = F.Exp();
    // PRINT(F);
    for (int i = 2; i <= n; i++) {
        int P = modpow(A[0], 1LL*i*(i-1)/2);
        cout << modmul(P, modmul(fac[i], F[i])) << (i==n ? '\n' : ' ');
    }

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 5ms
memory: 7732kb

input:

4 0
2

output:

2 8 64

result:

ok 3 number(s): "2 8 64"

Test #2:

score: 0
Accepted
time: 6ms
memory: 7892kb

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: 5ms
memory: 7716kb

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: 2ms
memory: 7716kb

input:

7 3
8 9 10 11

output:

17 5427 31856976 326774674 449014006 997476587

result:

ok 6 numbers

Test #5:

score: 0
Accepted
time: 19ms
memory: 7896kb

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: 18ms
memory: 7740kb

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: 19ms
memory: 7756kb

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: 14ms
memory: 7724kb

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: 226ms
memory: 12984kb

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: 222ms
memory: 12960kb

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: 218ms
memory: 13012kb

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: 222ms
memory: 13080kb

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: 219ms
memory: 13076kb

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: 342ms
memory: 13112kb

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: 343ms
memory: 13060kb

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: 339ms
memory: 13172kb

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: 342ms
memory: 13164kb

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: 39ms
memory: 8200kb

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: 334ms
memory: 13084kb

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: 339ms
memory: 13112kb

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: 334ms
memory: 13108kb

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: 342ms
memory: 13092kb

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: 338ms
memory: 13092kb

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: 38ms
memory: 8196kb

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: 223ms
memory: 13008kb

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: 346ms
memory: 13120kb

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: 347ms
memory: 13136kb

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