QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#633850#9451. Expected Waiting Timeucup-team4474#TL 972ms4100kbC++202.4kb2024-10-12 16:18:342024-10-12 16:18:36

Judging History

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

  • [2024-10-12 16:18:36]
  • 评测
  • 测评结果:TL
  • 用时:972ms
  • 内存:4100kb
  • [2024-10-12 16:18:34]
  • 提交

answer

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

bool Memory_begin;

/*
-2 0 0 2
-5 -1 -1 1 1 5
-14 -4 -4 0 0 4 4 14
-42 -14 -14 -4 -4 4 4 14 14 42
-132 -48 -48 -20 -20 0 0 20 20 48 48 132
-429 -165 -165 -81 -81 -25 -25 25 25 81 81 165 165 429
-1430 -572 -572 -308 -308 -140 -140 0 0 140 140 308 308 572 572 1430
*/

bool Memory_end;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cerr << (&Memory_end - &Memory_begin) / 1048576.0 << "MB" << '\n';

    int t;
    cin >> t;
    while (t--)
    {
        int n, p, A, B;
        cin >> n >> p;
        vector<int> b(n * 2 + 1), f(n * 2 + 1);
        vector<long long> a(n * 2 + 1);
        cin >> b[0] >> A >> B;
        for (int i = 1; i <= n * 2; i++)
        {
            b[i] = (1ll * A * b[i - 1] % p + B) % p;
            a[i] = a[i - 1] + b[i] + 1;
        }

        vector<int> fac(n * 2 + 1), ifac(n * 2 + 1);
        fac[0] = ifac[0] = 1;
        for (int i = 1; i <= n * 2; i++)
            fac[i] = 1ll * fac[i - 1] * i % p;
        auto inv = [&](int x) -> int
        {
            int y = p - 2, res = 1;
            while (y)
            {
                if (y & 1)
                    res = 1ll * res * x % p;
                x = 1ll * x * x % p;
                y >>= 1;
            }
            return res;
        };
        ifac[n * 2] = inv(fac[n * 2]);
        for (int i = n * 2 - 1; i >= 1; i--)
            ifac[i] = 1ll * ifac[i + 1] * (i + 1) % p;
        auto binom = [&](int x, int y) -> int
        {
            return 1ll * fac[x] * ifac[y] % p * ifac[x - y] % p;
        };
        vector<int> c(n), d(n);
        c[0] = 1;
        for (int i = 1; i < n; i++)
            c[i] = (binom(i * 2, i) + p - binom(i * 2, i + 1)) % p;
        for (int i = 0; i < n; i++)
            d[i] = 1ll * c[i] * c[n - i - 1] % p;
        for (int i = 1; i < n; i++)
            d[i] = (d[i] + d[i - 1]) % p;

        for (int i = 1; i < n * 2; i++)
        {
            int cnt = (2 * n - i - 1) / 2;
            f[i] = (f[i] - d[cnt] + p) % p;
        }
        for (int i = 2; i <= n * 2; i++)
        {
            int cnt = (i - 2) / 2;
            f[i] = (f[i] + d[cnt]) % p;
        }

        int ans = 0;
        for (int i = 1; i <= n * 2; i++)
            ans = (ans + 1ll * a[i] % p * f[i] % p) % p;
        ans = 1ll * ans * inv(d.back()) % p;
        cout << ans << '\n';
    }
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3884kb

input:

5
1 1000000007 0 1 0
2 1000000007 0 1 1
2 7 5 2 3
3 31 15 6 24
20 1000000007 0 1 0

output:

1
12
1
21
879705565

result:

ok 5 number(s): "1 12 1 21 879705565"

Test #2:

score: 0
Accepted
time: 972ms
memory: 4100kb

input:

4400
3954 1000000007 0 1 0
1306 1000000007 0 1 0
3774 1000000007 0 1 0
3345 1000000007 0 1 0
891 1000000007 0 1 0
2462 1000000007 0 1 0
237 1000000007 0 1 0
26 1000000007 0 1 0
2510 1000000007 0 1 0
637 1000000007 0 1 0
3250 1000000007 0 1 0
3447 1000000007 0 1 0
1222 1000000007 0 1 0
133 1000000007...

output:

440618338
378292891
979368645
915766295
343598158
80867595
161627927
517387931
396936703
42785642
945720545
764273281
186237656
635777911
164064906
548455037
991964184
468137124
561243246
118562285
856945294
642467240
23673926
808943705
897417615
462422554
656411244
204288121
997894281
244685651
762...

result:

ok 4400 numbers

Test #3:

score: -100
Time Limit Exceeded

input:

1019
338 1863833207 1820742817 1507924477 1822273457
770 1386304741 1088481071 1216187083 170973217
597 1604266739 620750027 196415899 456280997
105 1008587891 184044403 24836083 926135599
357 1165127407 440925347 1103369747 912263123
82 1639766993 263045351 631010551 1412721139
928 1715915153 25383...

output:

688317370
-111731908
1263157091
827110887
719114987
492078508
415469596
226745240
492483180
1018549875
659325143
977929696
1115735007
1031990493
1765247558
1360094517
-310356350
268011584
602319434
887965945
510644661
799628227
1090708543
1476703604
558752169
1050819260
-552172049
844160548
74689845...

result: