QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#250105#7620. Yet Another Subsequence Problemucup-team2307TL 269ms3868kbC++202.4kb2023-11-12 21:24:382023-11-12 21:24:39

Judging History

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

  • [2023-11-12 21:24:39]
  • 评测
  • 测评结果:TL
  • 用时:269ms
  • 内存:3868kb
  • [2023-11-12 21:24:38]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
//#define int ll

const int MOD=998244353;

#if 1
using row=array<int,3>;
using matr=array<row,3>;
const matr ONE={
    row{1,0,0},
    row{0,1,0},
    row{0,0,1}
};
matr mul(matr l,matr r)
{
    matr res{};
    for (int i = 0; i < 3; ++i)
        for (int j = 0; j < 3; j++)
        {
            res[i][j]=((ll)l[i][0]*r[0][j]+(ll)l[i][1]*r[1][j]+(ll)l[i][2]*r[2][j])%MOD;
        }
    return res;
}
const matr X={
    row{1,0,0},
    row{1,1,0},
    row{1,0,1}
};
const matr Y={
    row{1,1,0},
    row{0,1,0},
    row{0,1,1}
};
const matr invX={
        row{1,0,0},
        row{MOD-1,1,0},
        row{MOD-1,0,1}
};
const matr invY={
        row{1,MOD-1,0},
        row{0,1,0},
        row{0,MOD-1,1}
};
auto ret(matr res)
{
    return (res[2][0]+res[2][1]+1)%MOD;
}
#else
using matr=string;
const matr ONE;
matr mul(const matr& l,const matr& r)
{
    return l+r;
}
const matr X="1";
const matr Y="0";
auto ret(matr res)
{
    return res;
}
#endif

matr pow(matr x,int y)
{
    matr res=ONE;
    while(y)
    {
        if(y&1)
            res=mul(res,x);
        y>>=1;
        x=mul(x,x);
    }
    return res;
}

matr rec(ll a, ll b, matr x, matr y)
{
    while(a>1||b>1)
    {
//        cout << a << " " << b << " " << x << " " << y << "\n";
        matr xx=mul(pow(x, b / a - 1),y);
        matr yy=mul(x,xx);
        tie(a, b, y, x)=tuple(a - b % a, a, xx, yy);
    }
    return y;
}

auto solve(ll a,ll b)
{
    ll g=__gcd(a,b);
    bool sw=a>b;
    if(sw)
        swap(a,b);
    matr res=rec(a/g,b/g,Y,mul(X,Y));
    if(!sw)
    {
        res=mul(res,invY);
        res=mul(res,invX);
        res=mul(res,Y);
        res=mul(res,X);
    }
    res=pow(res,g);
    return ret(res);
}

std::string gen_string(int64_t a, int64_t b) {
    std::string res;
    int64_t ia = 0, ib = 0;
    while (ia + ib < a + b) {
        if ((__int128)ia * b <= (__int128)ib * a) {
            res += '0';
            ia++;
        } else {
            res += '1';
            ib++;
        }
    }
    reverse(res.begin(),res.end());
    return res;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin>>t;
    while(t--)
    {
        ll a,b;
        cin>>a>>b;
//        cout<<gen_string(a,b)<<"\n";
        cout<<solve(a,b)<<"\n";
    }
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3568kb

input:

6
1 1
3 5
4 7
8 20
4 10
27 21

output:

4
70
264
196417
609
667131122

result:

ok 6 numbers

Test #2:

score: 0
Accepted
time: 269ms
memory: 3568kb

input:

18
5 9
23 30
820 483
5739 9232
86494 55350
606 13336
2768848 1124639
47995594 66053082
1069395 7177
7801842511 4390103762
47882886553 82678306054
193410894 6189355686
51594638 19992922190
59 110
422735115778072 658356435030265
9125338158530266 5328357177709583
60743352262021049 95595862538791630
629...

output:

988
220693002
133474535
202371605
778839228
282057418
935955056
943144752
409056617
627433544
578769776
917438628
24364208
109943645
352575425
68058533
402004723
894026897

result:

ok 18 numbers

Test #3:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

9
7 6
4 7
1 1
1 1
2 1
8 5
4 7
4 7
8 8

output:

986
264
4
4
7
781
264
264
4180

result:

ok 9 numbers

Test #4:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

7
10 10
9 5
5 9
5 8
7 4
5 9
4 8

output:

28656
1100
988
702
294
988
361

result:

ok 7 numbers

Test #5:

score: 0
Accepted
time: 0ms
memory: 3664kb

input:

10
4 7
5 9
9 5
5 9
7 4
9 9
3 10
7 4
9 5
6 4

output:

264
988
1100
988
294
10945
253
294
1100
207

result:

ok 10 numbers

Test #6:

score: 0
Accepted
time: 0ms
memory: 3788kb

input:

9
77 47
65 37
96 59
74 45
96 61
66 47
53 73
41 72
47 64

output:

477691493
223541570
510016172
616252466
634241188
463620644
498542012
162791920
984013116

result:

ok 9 numbers

Test #7:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

8
41 69
86 51
44 88
47 66
71 44
47 77
44 44
9 17

output:

856129900
783572707
168948980
519731719
796410895
739386210
133340520
191860

result:

ok 8 numbers

Test #8:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

9
47 73
99 15
52 73
29 52
82 53
49 78
71 40
50 87
84 53

output:

769345491
690191730
757588716
658697918
61904949
629708093
220994184
297434348
28621139

result:

ok 9 numbers

Test #9:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

7
661 462
386 656
797 510
19 2
685 406
994 984
86 165

output:

108717767
243878739
146514460
348
433968238
266547073
518079889

result:

ok 7 numbers

Test #10:

score: 0
Accepted
time: 0ms
memory: 3508kb

input:

7
640 391
187 37
185 77
758 530
690 708
614 422
745 596

output:

568664902
101789251
757511817
887691770
177453450
32893736
437096982

result:

ok 7 numbers

Test #11:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

8
813 469
744 999
637 437
394 303
773 773
380 643
38 9
703 426

output:

454035451
338288113
916487884
221556201
179854568
52657041
26618143
962558445

result:

ok 8 numbers

Test #12:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

8
6855 4213
4112 6914
5778 2583
4988 8449
8090 8090
6519 4733
4434 6958
2 3

output:

427280974
44013214
375314206
144262561
427379094
372013990
839270931
18

result:

ok 8 numbers

Test #13:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

8
8409 5416
8107 4913
95 98
115 3
5013 7048
9328 5735
1680 5712
5197 7557

output:

894035672
40190853
343168705
190160
390361879
183351154
606244444
134913462

result:

ok 8 numbers

Test #14:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

9
5182 8121
3750 6458
8234 8234
4143 7423
4020 1789
4107 7290
6723 3999
4268 6070
7780 3890

output:

866885729
688535194
823578849
212358139
362917931
67863647
455387876
758964821
193741943

result:

ok 9 numbers

Test #15:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

7
61155 95200
45410 29617
52271 72405
65732 48477
24291 69219
67575 35139
79612 44714

output:

568124700
703486037
744399547
157090122
340253631
764313623
405183638

result:

ok 7 numbers

Test #16:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

9
58285 95000
61322 43451
62444 98391
63929 37316
11880 85320
55132 89028
46015 74851
95036 57832
97346 57569

output:

198194769
642221077
706321582
889996800
236557792
438005278
854653054
551428347
412917166

result:

ok 9 numbers

Test #17:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

9
70070 51175
1 3
97696 89440
76449 76449
39928 68508
53907 53907
48569 83915
64151 44772
423 4

output:

386957046
8
333547672
669126229
622003028
967849140
694422542
68403374
399271894

result:

ok 9 numbers

Test #18:

score: 0
Accepted
time: 1ms
memory: 3632kb

input:

7
791062 495727
446934 701097
575527 973782
601232 973330
1293 33622
654288 790598
582881 422021

output:

787234183
89769894
656957068
144699935
985638
436404539
589184034

result:

ok 7 numbers

Test #19:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

9
170761 370325
835313 538289
557394 885834
4 1370
457105 725030
170133 373897
606675 954589
478770 675786
529800 529800

output:

938892037
351941869
451634146
177505605
507054806
847951838
454269997
734099694
483445163

result:

ok 9 numbers

Test #20:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

9
971470 571018
729856 522877
712674 782955
527307 855805
1991 6
646650 479073
664436 461056
543147 736991
1027 2

output:

701913251
360490926
401476354
140864080
439953424
58245462
571144790
226876232
795156

result:

ok 9 numbers

Test #21:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

7
4220475 7200014
8946114 5607972
9217056 5889071
216495 8018
9263205 6175470
9381418 5709506
1305186 5438275

output:

416147761
504552270
531404017
597473622
227696082
526572165
932407358

result:

ok 7 numbers

Test #22:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

8
4735393 5463915
50137 654914
2203 4
2925479 5850958
5159591 8973433
7313341 4117661
5899 8
9318992 5940830

output:

830746100
701627501
861951012
734922707
586974926
54838635
54717862
962062441

result:

ok 8 numbers

Test #23:

score: 0
Accepted
time: 0ms
memory: 3512kb

input:

8
4808286 7533233
5427286 7627443
7049100 4420557
8918768 5668723
674651 626518
4540185 161190
1410422 8462532
7049224 4534562

output:

228187053
202526633
99774240
904698472
480292240
855142423
37675392
981266426

result:

ok 8 numbers

Test #24:

score: 0
Accepted
time: 0ms
memory: 3868kb

input:

10
33704480 11375262
63375993 63375993
12 13
58407009 98800752
10 7
381848 5348452
88342222 50792883
55352977 76210207
361275 3998109
58416656 94841469

output:

649109810
36477705
289153
752071377
5394
292760513
85444308
575684169
613771553
675962623

result:

ok 10 numbers

Test #25:

score: 0
Accepted
time: 1ms
memory: 3864kb

input:

7
34852528 49858286
62481622 49765513
75583113 25194371
3229939 804483
58329210 93597303
23508450 62689200
5 8

output:

391402413
137652286
768999263
472921885
836021626
100793612
702

result:

ok 7 numbers

Test #26:

score: 0
Accepted
time: 1ms
memory: 3564kb

input:

8
57310378 88790898
13 9147
1549494 24595
8452791 2087427
21621 172979
73536914 41674942
10163116 31757473
55581659 88587394

output:

41887077
681921806
26003660
68330985
630056979
227526752
694974420
566287628

result:

ok 8 numbers

Test #27:

score: 0
Accepted
time: 0ms
memory: 3512kb

input:

10
698700042 449659396
17 13
43899392 51200357
895050714 895050714
643725501 382794307
458560944 776109451
567286349 962689176
149158675 24522207
440485810 690959859
652728768 598334704

output:

703577031
2520080
194426181
120762097
456471628
53917573
344514670
705330170
462968000
697259102

result:

ok 10 numbers

Test #28:

score: 0
Accepted
time: 1ms
memory: 3564kb

input:

9
172917712 875395917
897335234 563015871
745518604 471032145
745253836 526187524
745397239 521218138
618365020 879980990
2609837 36375280
100674 7248541
405784272 696239702

output:

26528974
235341182
719622291
725483715
162432807
573688992
359069671
123532858
850989940

result:

ok 9 numbers

Test #29:

score: 0
Accepted
time: 1ms
memory: 3516kb

input:

8
19 16
919871160 979626570
652248464 796017040
513535282 890441475
587071118 935031010
566303476 566303476
853646878 518444900
54282 6459567

output:

31270230
469453648
140433663
633373156
490180087
832298148
445105898
409991300

result:

ok 8 numbers

Test #30:

score: 0
Accepted
time: 2ms
memory: 3568kb

input:

10
6316442971 3717676023
5707194159 9738462445
24455 10613497
4573236121 6647697858
4262400710 7167730777
270056596 1125156154
4585295484 4280782059
2130266613 431444507
7969708160 2789397856
6217859616 4582712819

output:

41234471
962654143
239500287
741697872
114104471
165586759
197355975
854304368
867087760
128591444

result:

ok 10 numbers

Test #31:

score: -100
Time Limit Exceeded

input:

8
4579668169 6390539165
1041646110 571219849
30 251
9 9
4671515135 7856932100
263421185 13851483
8361459884 4180729942
5455444332 8540064262

output:


result: