UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#207752#3768. 前缀和tanghexuan100353ms1264kbC++112.3kb2024-07-30 19:13:272024-07-30 20:06:23

answer

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

static auto __fast_io = []()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    return 0;
}();

const long long MOD = 998244353;

long long sum;
long long a[3][3][3];
long long sz;
long long ans;
long long n, m;
long long a1;

void merge()
{
    for (int i = 1; i <= sz; i++)
    {
        for (int j = 1; j <= sz; j++)
        {
            a[2][i][j] = 0;
        }
    }
    for (int k = 1; k <= sz; k++)
    {
        for (int i = 1; i <= sz; i++)
        {
            for (int j = 1; j <= sz; j++)
            {
                a[2][i][j] = (a[2][i][j] + 1ll * a[0][i][k] * a[1][k][j] % MOD) % MOD;
            }
        }
    }
    for (int i = 1; i <= sz; i++)
    {
        for (int j = 1; j <= sz; j++)
        {
            a[0][i][j] = a[2][i][j];
        }
    }
}
void merge2()
{
    for (int i = 1; i <= sz; i++)
    {
        for (int j = 1; j <= sz; j++)
        {
            a[2][i][j] = 0;
        }
    }
    for (int k = 1; k <= sz; k++)
    {
        for (int i = 1; i <= sz; i++)
        {
            for (int j = 1; j <= sz; j++)
            {
                a[2][i][j] = (a[2][i][j] + 1ll * a[1][i][k] * a[1][k][j] % MOD) % MOD;
            }
        }
    }
    for (int i = 1; i <= sz; i++)
    {
        for (int j = 1; j <= sz; j++)
        {
            a[1][i][j] = a[2][i][j];
        }
    }
}
void qpow(long long k)
{
    while (k)
    {
        if (k & 1)
        {
            merge();
        }
        k >>= 1, merge2();
    }
}

void input()
{
    cin >> n >> m >> a1;
}
void work()
{
    ans = a1;
    if (n == 1)
        return;
    sum = a1;
    a1 = (a1 + m) % MOD;
    sum = (sum + a1) % MOD;
    sz = 2;
    ans = a1;
    if (n == 2)
        return;
    a[0][1][1] = a[1][1][1] = 1;
    a[0][1][2] = a[1][1][2] = 1;
    a[0][2][1] = a[1][2][1] = 1;
    a[0][2][2] = a[1][2][2] = 2;
    qpow(n - 3);
    // cout << a[0][1][1] << " " << a[0][1][2] << "\n"
    //      << a[0][2][1] << " " << a[0][2][2] << "\n";
    ans = (a1 * a[0][1][1] % MOD + sum * a[0][2][1] % MOD) % MOD;
}
void output()
{
    cout << ans << "\n";
}

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        input();
        work();
        output();
    }
    return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 5
Accepted
time: 2ms
memory: 1252kb

input:

10
999999999999999986 0 0
999999999999999991 0 0
999999999999999986 0 0
999999999999999990 0 0
99999...

output:

0
0
0
0
0
0
0
0
0
0

result:

ok 10 tokens

Test #2:

score: 5
Accepted
time: 0ms
memory: 1252kb

input:

10
27 394502328 704811141
47 510615886 836016431
16 732949912 873777233
79 224767945 584300306
53 30...

output:

160618586
476183477
214301529
414736331
938410338
82327142
869636405
823074181
422516300
448110017

result:

ok 10 tokens

Test #3:

score: 5
Accepted
time: 0ms
memory: 1252kb

input:

10
29 908698706 656415656
73 340081904 666753583
49 120165406 827255677
97 263886512 115978477
82 66...

output:

160726921
638373664
232231434
871012536
815009338
728544551
50311973
777278980
408066846
558124020

result:

ok 10 tokens

Test #4:

score: 5
Accepted
time: 1ms
memory: 1256kb

input:

10
24 815392212 158893485
20 106120120 720966485
92 648620121 971073137
62 498389918 955366970
82 26...

output:

741412002
353232419
34176144
82618274
976902741
715176801
432908882
726507952
708781305
404405255

result:

ok 10 tokens

Test #5:

score: 5
Accepted
time: 0ms
memory: 1256kb

input:

10
70 732781470 451862750
92 798448019 55096155
12 15503873 809457172
14 40178736 938171637
24 46560...

output:

515697521
557889800
512673707
477751970
987771721
567871458
232309233
89218141
795002894
97446047

result:

ok 10 tokens

Test #6:

score: 5
Accepted
time: 0ms
memory: 1256kb

input:

10
90861 712228743 749715339
95966 781209778 254301776
98144 170363142 307595582
91210 416894520 638...

output:

292485125
850171336
715786758
176835506
175415901
868198851
713190399
720535252
477887669
297230688

result:

ok 10 tokens

Test #7:

score: 5
Accepted
time: 0ms
memory: 1256kb

input:

10
96965 61379038 717756665
92445 534127283 810781
91661 715004088 386864844
96077 998191859 7505735...

output:

156264360
863310397
81277953
397897589
201490186
141245808
908220821
563550625
715992949
661738617

result:

ok 10 tokens

Test #8:

score: 5
Accepted
time: 0ms
memory: 1256kb

input:

10
99933 66908597 322574074
91563 578926670 893590152
99169 236501165 765826017
92515 447113057 5702...

output:

686087351
58309551
974352798
610094900
957106431
163643067
624245753
241163529
797689675
381828044

result:

ok 10 tokens

Test #9:

score: 5
Accepted
time: 0ms
memory: 1252kb

input:

10
98828 858750825 240386766
97500 773682411 656804902
95454 384008018 86113615
91531 665213365 2454...

output:

667110960
546827786
290618289
930702000
248338295
547142281
741290046
566334453
948532487
497944652

result:

ok 10 tokens

Test #10:

score: 5
Accepted
time: 0ms
memory: 1256kb

input:

10
93993 886800232 31886870
96268 670777364 750304002
98194 744064661 661110190
96013 817065125 9793...

output:

248811671
155899040
165284489
657313874
709550487
730945895
400758785
550263902
184462463
808202166

result:

ok 10 tokens

Test #11:

score: 5
Accepted
time: 51ms
memory: 1264kb

input:

10000
948988045411931137 751774918 773912726
891963022064669013 83439223 789646374
89051487168077280...

output:

785992168
313848750
235996494
227454577
741354002
218864722
938425671
552730236
761659241
292493851
...

result:

ok 10000 tokens

Test #12:

score: 5
Accepted
time: 32ms
memory: 1260kb

input:

10000
968968049383870965 470248529 961624741
860673561734227447 711687580 118322830
9466678457088250...

output:

729956199
138123590
161870128
953945742
781767611
799768381
60045928
319331437
797215528
551833902
7...

result:

ok 10000 tokens

Test #13:

score: 5
Accepted
time: 27ms
memory: 1264kb

input:

10000
996210840763184150 379435044 46240715
957009670203095182 588621962 32413727
856934457131434374...

output:

310767600
494132439
538321141
225470957
540003477
282468210
23756325
469909035
969988279
393290109
8...

result:

ok 10000 tokens

Test #14:

score: 5
Accepted
time: 32ms
memory: 1264kb

input:

10000
970160076699975721 930768296 715181844
830949224459356803 149622331 309970800
9633604039243290...

output:

911032544
79171930
416298777
431113078
969154296
70994303
50903354
522899447
730731878
200341098
225...

result:

ok 10000 tokens

Test #15:

score: 5
Accepted
time: 35ms
memory: 1264kb

input:

10000
827399062500306535 33823512 734207105
879991131082945309 912461337 202773779
85164585824309648...

output:

601242493
789072308
707319827
521247231
306993447
566873061
914382254
271684511
298413011
243752100
...

result:

ok 10000 tokens

Test #16:

score: 5
Accepted
time: 36ms
memory: 1260kb

input:

10000
983908774640419308 982881132 284763245
801568586504883055 349860149 784194606
8609838332297830...

output:

633478384
103794889
199094092
351805716
553385055
750344701
994135993
976650811
353338344
287684713
...

result:

ok 10000 tokens

Test #17:

score: 5
Accepted
time: 33ms
memory: 1260kb

input:

10000
956266530657999088 230426943 322792594
865462860372890442 282800560 437826068
8094928333904686...

output:

309593356
914778841
783405533
781603906
40240827
129200969
654363281
364282446
516066948
596603515
5...

result:

ok 10000 tokens

Test #18:

score: 5
Accepted
time: 31ms
memory: 1264kb

input:

10000
868728608212628642 901844081 77140512
891643586872337125 836835987 606467274
85304317438290743...

output:

634718867
777442571
718892236
474370428
277971334
204179007
778820918
298571673
268095331
232597253
...

result:

ok 10000 tokens

Test #19:

score: 5
Accepted
time: 31ms
memory: 1260kb

input:

10000
852634689738822825 549739895 925465063
939009093749329366 27841760 979946868
87324086040186925...

output:

221764219
928798241
203638368
785150239
500009117
206266032
954050869
819652458
29668451
109393173
7...

result:

ok 10000 tokens

Test #20:

score: 5
Accepted
time: 42ms
memory: 1264kb

input:

10000
915194648289131487 592352670 609557926
897573010199961785 470530638 950622317
9272047252782130...

output:

69870913
744240613
97734943
916935284
994957761
480078547
782165495
840835673
802288286
144223224
92...

result:

ok 10000 tokens