QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#481039#621. 多项式指数函数Gold_Dino#0 299ms32336kbC++145.3kb2024-07-16 20:11:042024-07-16 20:11:04

Judging History

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

  • [2024-07-16 20:11:04]
  • 评测
  • 测评结果:0
  • 用时:299ms
  • 内存:32336kb
  • [2024-07-16 20:11:04]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string.h>
#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int Q = 998244353, G = 3;
const int MaxN = 16e6 + 7;
int qpow(int a, int n)
{
    int bas = 1;
    while (n)
    {
        if (n & 1)
            (bas *= a) %= Q;
        (a *= a) %= Q, n >>= 1;
    }
    return bas;
}
int inv(int a) { return qpow(a, Q - 2); }
const int ivG = inv(G);
int tr[MaxN];
inline void tpre(int len)
{
    for (int i = 1; i < len; ++i)
    {
        tr[i] = tr[i >> 1] >> 1;
        if (i & 1)
            tr[i] |= len >> 1;
    }
}
template <class Tp>
inline void clr(Tp *f, int len) { memset(f, 0, sizeof(Tp) * len); }
template <class Tp>
inline void cpy(Tp *f, Tp *g, int len) { memcpy(f, g, sizeof(Tp) * len); }
void NTT(int *f, bool tp, int len)
{
    static ull t1[MaxN], t2[MaxN];
    t2[0] = 1;
    tpre(len);
    for (int i = 0; i < len; ++i)
        t1[i] = f[tr[i]];
    for (int i = 1, c = 0; i < len; i <<= 1, ++c)
    {
        ull wn = qpow(tp ? G : ivG, (Q - 1) / (i + i));
        for (int j = 1; j < i; ++j)
            t2[j] = t2[j - 1] * wn % Q;
        for (int j = 0; j < len; j += i)
            for (int k = 0; k < i; ++k)
            {
                ull t = t1[i | j | k] * t2[k] % Q;
                t1[i | j | k] = t1[j | k] + Q - t;
                t1[j | k] += t;
            }
        if (c % 10 == 0 && c)
            for (int j = 0; j < len; ++j)
                t1[j] %= Q;
    }
    if (tp)
        for (int i = 0; i < len; ++i)
            f[i] = t1[i] % Q;
    else
    {
        ull ivl = inv(len);
        for (int i = 0; i < len; ++i)
            f[i] = t1[i] % Q * ivl % Q;
    }
}
void vmul(int *f, int *g, int len)
{
    for (int i = 0; i < len; ++i)
        f[i] = 1ll * f[i] * g[i] % Q;
}
void times(int *f, int *g, int m1, int m2)
{
    int len = 1 << (32 - __builtin_clz(m1 + m2 - 2));
    clr(f + m1, len - m1), clr(g + m2, len - m2);
    NTT(f, 1, len), NTT(g, 1, len);
    vmul(f, g, len);
    NTT(f, 0, len), NTT(g, 0, len);
}
void inver(int *h, int *f, int len)
{
    int n = 1;
    f[0] = inv(h[0]);
    static int w1[MaxN], w2[MaxN];
    while (n < len)
    {
        clr(f + n, n);
        cpy(w1, h, n + n);
        cpy(w2, f, n), clr(w2 + n, n);
        NTT(w1, 1, n + n), NTT(w2, 1, n + n);
        vmul(w1, w2, n + n);
        NTT(w1, 0, n + n), clr(w1, n);
        NTT(w1, 1, n + n), vmul(w1, w2, n + n);
        NTT(w1, 0, n + n);
        for (int i = n; i < n + n; ++i)
            f[i] = (Q - w1[i]) % Q;
        n <<= 1;
    }
    clr(f + len, n - len);
}
void ints(int *f, int len)
{
    for (int i = len + 1; i; --i)
        f[i] = 1ll * f[i - 1] * inv(i) % Q;
    f[0] = 0;
}
void wers(int *f, int len)
{
    for (int i = 0; i < len - 1; ++i)
        f[i] = 1ll * f[i + 1] * (i + 1) % Q;
    f[len] = 0;
}
void lnp(int *f, int *g, int len)
{
    static int w1[MaxN], w2[MaxN];
    cpy(w1, f, len), wers(w1, len);
    inver(f, w2, len);
    times(w1, w2, len, len);
    ints(w1, len);
    cpy(g, w1, len);
}
void pexp(int *h, int *f, int len)
{
    int n = 2;
    f[0] = 1;
    static int w1[MaxN], w2[MaxN];
    while (n < len + len)
    {
        clr(f + (n >> 1), n + (n >> 1));
        lnp(f, w1, n), clr(w1 + n, n);
        cpy(w2, h, n), clr(w2 + n, n);
        NTT(f, 1, n + n), NTT(w1, 1, n + n), NTT(w2, 1, n + n);
        for (int i = 0; i < n + n; ++i)
            f[i] = 1ll * (1 + Q - w1[i] + w2[i]) % Q * f[i] % Q;
        NTT(f, 0, n + n);
        clr(f + n, n);
        n <<= 1;
    }
    clr(f + len, n - len);
}
void powp(int *h, int *f, int k, int len)
{
    static int w[MaxN];
    lnp(h, w, len);
    for (int i = 0; i < len; ++i)
        w[i] = 1ll * w[i] * k % Q;
    pexp(w, f, len);
}
ll si;
struct Complex
{
    ll a, b;
    Complex operator*(const Complex x) const { return (Complex){(a * x.a + b * x.b % Q * si) % Q, (a * x.b + b * x.a) % Q}; }
};
mt19937_64 my_rand(11451467);
Complex qpow(Complex a, int n)
{
    Complex bas{1, 0};
    while (n)
    {
        if (n & 1)
            bas = bas * a;
        a = a * a, n >>= 1;
    }
    return bas;
}
ll sq(ll n)
{
    ll x;
    while (1)
    {
        x = my_rand() % Q;
        if (qpow((x * x + Q - n) % Q, (Q - 1) / 2) == Q - 1)
            break;
    }
    si = (x * x + Q - n) % Q;
    Complex a(qpow((Complex){x, 1}, (Q + 1) / 2));
    return min(a.a, (Q - a.a) % Q);
}
void sqrtp(int *h, int *f, int len)
{
    int n = 2;
    static int w1[MaxN], w2[MaxN];
    f[0] = sq(h[0]);
    ll iv2 = inv(2);
    while (n < len + len)
    {
        clr(f + (n >> 1), n >> 1);
        cpy(w1, h, n), clr(w1 + n, n);
        inver(f, w2, n), clr(w2 + n, n);
        NTT(f, 1, n + n), NTT(w1, 1, n + n), NTT(w2, 1, n + n);
        for (int i = 0; i < n + n; ++i)
            f[i] = 1ll * (1ll * f[i] * f[i] % Q + w1[i]) % Q * w2[i] % Q * iv2 % Q;
        NTT(f, 0, n + n);
        clr(f + n, n);
        n <<= 1;
    }
    clr(f + len, n - len);
}
int f[MaxN], g[MaxN], h[MaxN];
int main()
{
    int m, k, i;
    scanf("%d", &m);
    for (i = 0; i < m; ++i)
        scanf("%d", f + i);
    pexp(f, g, m);
    for (i = 0; i < m; ++i)
        printf("%d ", g[i]);
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 24184kb

input:

100
0 158447743 737554986 671332600 489297184 754299210 115728600 816221630 819073359 691660913 910093246 562505672 355119917 385019894 611338034 123976316 122342952 82142434 796101450 994778874 575255638 493217967 652609142 662045597 783871340 470398790 241710709 754059035 534582325 836438174 95789...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

result:

wrong answer 1st numbers differ - expected: '1', found: '0'

Test #2:

score: 0
Wrong Answer
time: 19ms
memory: 24092kb

input:

5000
0 354399910 26360255 630255958 717224815 366941345 333979504 905420494 38176634 475666562 611197455 433060682 509600868 845217181 520468365 529689763 431747498 192834976 685184103 287994809 273221518 522219732 427553800 10872482 525061651 448069946 183539744 610476003 840167561 241104955 404100...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

wrong answer 1st numbers differ - expected: '1', found: '0'

Test #3:

score: 0
Wrong Answer
time: 71ms
memory: 24168kb

input:

30000
0 147199510 293972908 780683378 633744119 800282266 162025013 919460711 939176222 298044997 277962122 729446209 455723129 756791462 84697115 579989768 945113433 549318980 229266945 869577376 103161009 960973464 440149102 836285074 687333626 638404974 184096947 370164754 454531549 142629528 150...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

wrong answer 1st numbers differ - expected: '1', found: '0'

Test #4:

score: 0
Wrong Answer
time: 299ms
memory: 32336kb

input:

100000
0 279349013 196667718 617497154 78288698 996674429 180463729 304956112 173800460 352061138 224505321 119706982 726737325 564797383 757014824 888433954 747100108 723246918 645172013 184990722 321964667 456686646 138153830 701558524 317746193 650472945 49496183 864461799 982372868 582778782 242...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

wrong answer 1st numbers differ - expected: '1', found: '0'

Test #5:

score: 0
Time Limit Exceeded

input:

1000000
0 204517192 162156394 729093416 352181074 335898409 357987855 386581690 26622360 437289663 34104646 938411413 659876244 293619518 291093969 909364118 179765868 89417259 632261731 375051702 493701794 771716785 682264158 329653513 86558030 9195128 957504298 22555222 384175297 128022431 5957444...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result: