UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215359#2162. 无限手套nodgd100608ms1368kbC++111.2kb2024-11-28 21:03:052024-11-28 23:12:14

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
const int MAX_M = 1000 + 5;
const int MAX_N = 10000 + 5;
const int P = 998244353;

int M, Q, N;
int va[MAX_N], vb[MAX_N];
int qn[MAX_N];
int f[MAX_N], g[MAX_N], h[MAX_N], p[MAX_N];

int main() {
    scanf("%d", &M);
    for (int i = 1; i <= M; i ++) {
        scanf("%d%d", &va[i], &vb[i]);
    }
    scanf("%d", &Q);
    for (int i = 1; i <= Q; i ++) {
        scanf("%d", &qn[i]);
        N = max(N, qn[i]);
    }
    f[0] = 1;
    for (int i = 1; i <= M; i ++) {
        i64 a = va[i] % P, b = vb[i] % P;
        i64 A = 2 * a % P;
        i64 B = (b - a * 3 + P * 3ll) % P;
        i64 C = (a - b + 1 + P) % P;
        g[0] = h[0] = p[0] = f[0];
        for (int j = 1; j <= N; j ++) {
            g[j] = g[j - 1] + f[j];
            g[j] -= g[j] >= P ? P : 0;
            h[j] = h[j - 1] + g[j];
            h[j] -= h[j] >= P ? P : 0;
            p[j] = p[j - 1] + h[j];
            p[j] -= p[j] >= P ? P : 0;
            f[j] = (C * g[j] + B * h[j] + A * p[j]) % P;
        }
    }
    for (int i = 1; i <= Q; i ++) {
        printf("%d\n", f[qn[i]]);
    }
    return 0;
}

详细

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

Test #1:

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

input:

10
21 59
15 27
62 71
100 98
88 16
62 25
88 66
72 71
29 31
1 0
10
2
2
3
2
4
5
8
5
6
5

output:

448551
448551
114612322
448551
728853470
277267547
83320298
277267547
38592888
277267547

result:

ok 10 lines

Test #2:

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

input:

17
73 29
79 15
100 35
34 97
39 50
3 48
45 68
47 50
3 28
73 85
89 87
55 46
14 54
49 88
42 73
44 2
16 ...

output:

114883454
27471359
887593781
827351165
86981973
827351165
1392510
114883454
1725
421716985
307599961...

result:

ok 17 lines

Test #3:

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

input:

20
27 19
18 92
81 51
63 60
32 34
51 84
33 42
74 60
77 36
6 21
24 17
75 92
31 53
31 80
8 30
79 26
83 ...

output:

992068581
1969
892548909
238165372
110008477
995194659
179471275
420889444
11928868
179471275
272422...

result:

ok 20 lines

Test #4:

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

input:

25
26 7
38 93
23 54
7 73
19 76
82 2
56 27
97 81
54 28
54 21
62 43
34 40
60 53
15 36
70 16
69 66
63 8...

output:

103269
734406478
345903674
359420380
880946160
271579155
32581827
880946160
966935950
611559579
4653...

result:

ok 25 lines

Test #5:

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

input:

27
80 18
40 71
21 78
53 67
24 18
97 21
56 24
10 32
36 17
48 23
45 44
77 94
93 11
35 32
52 57
73 51
6...

output:

410943243
721573301
181533076
668067998
682080677
863525129
63084931
705139901
452302283
245889941
1...

result:

ok 27 lines

Test #6:

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

input:

30
42 32
4 11
64 52
52 45
8 29
27 81
57 52
51 42
52 85
27 61
69 46
18 43
69 87
77 92
5 23
69 15
21 8...

output:

810744230
839400864
924094824
937834219
316524152
529862398
712976747
219997060
272438710
519978575
...

result:

ok 30 lines

Test #7:

score: 5
Accepted
time: 13ms
memory: 1300kb

input:

500
35 33
42 54
68 92
11 31
78 89
89 33
12 43
40 25
89 74
10 96
72 79
41 27
26 9
89 3
24 32
90 22
86...

output:

932312156
494146079
785555178
893796002
977269012
781615223
830979825
498559680
622697650
783110232
...

result:

ok 500 lines

Test #8:

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

input:

800
67 2
17 90
7 2
80 77
15 8
96 71
77 85
67 83
30 67
21 37
95 0
1 70
69 83
8 28
42 80
32 99
35 13
8...

output:

819268178
372512022
102392595
606603299
679104162
742087129
964962140
472029305
316420903
847635337
...

result:

ok 800 lines

Test #9:

score: 5
Accepted
time: 48ms
memory: 1364kb

input:

1000
117036880 742743701
56908371 507994295
14078772 65839630
907546488 34355343
620471543 368910184...

output:

461522957
903730716
165933947
31761347
91738778
851765265
980107979
991347870
825694579
853918437
81...

result:

ok 1000 lines

Test #10:

score: 5
Accepted
time: 48ms
memory: 1364kb

input:

1000
913953750 388577668
962198313 857512157
801529469 683598255
815720687 278538934
837931460 95491...

output:

612389072
663941278
17225937
951334721
867747447
689590705
268102230
301163238
68448422
283748746
59...

result:

ok 1000 lines

Test #11:

score: 5
Accepted
time: 48ms
memory: 1364kb

input:

1000
686221334 956155197
638206740 299677636
12110365 985957201
296066012 395725665
135750350 202076...

output:

616161259
866485600
452591851
123085226
883880314
899979440
90024622
5824195
547563606
149820827
637...

result:

ok 1000 lines

Test #12:

score: 5
Accepted
time: 48ms
memory: 1364kb

input:

1000
797564334 746000325
114543902 483936681
721653706 427330786
783028161 561100881
560205639 93358...

output:

387718885
796323491
347604564
21260297
989965572
425532127
15088496
19942812
706351242
537306504
896...

result:

ok 1000 lines

Test #13:

score: 5
Accepted
time: 48ms
memory: 1364kb

input:

1000
839212319 281284893
986615727 337004261
337283416 832217943
139479834 143482354
718642613 79109...

output:

709654221
284968005
853870769
244317442
373778049
106308969
562334630
521975360
617513615
90388845
7...

result:

ok 1000 lines

Test #14:

score: 5
Accepted
time: 49ms
memory: 1364kb

input:

1000
256682454 224905163
546469163 405500779
694909527 452737645
118757654 446812736
305219239 49932...

output:

361868779
913435998
464384758
556418430
709291536
677431761
482042298
424118253
104770879
147031476
...

result:

ok 1000 lines

Test #15:

score: 5
Accepted
time: 44ms
memory: 1364kb

input:

1000
896922349 6803764
761865535 943048070
88880191 606683203
70560593 543433355
840830392 692058868...

output:

758319401
712518977
740732861
380595967
393408896
160878359
102588355
265535173
812122783
380107764
...

result:

ok 1000 lines

Test #16:

score: 5
Accepted
time: 49ms
memory: 1368kb

input:

1000
449301829 90031054
325997406 72341047
30416088 913003710
735565029 221233542
491751571 62166318...

output:

259182799
801732641
895963304
728056440
147126321
73980793
152310331
425738358
420629754
906311422
4...

result:

ok 1000 lines

Test #17:

score: 5
Accepted
time: 44ms
memory: 1364kb

input:

1000
832954961 166377984
853572866 869031810
703004519 916522551
674441360 532019428
604496 80785481...

output:

121395962
300319725
321146992
893973609
682719650
596718568
423864083
251143397
891884443
140741137
...

result:

ok 1000 lines

Test #18:

score: 5
Accepted
time: 45ms
memory: 1368kb

input:

1000
630591319 431364812
551848923 931390133
383831685 842422164
638941693 967379955
11797927 362876...

output:

497539048
992868988
944184807
57452325
686959710
938074762
971500412
944069558
141704899
5157624
704...

result:

ok 1000 lines

Test #19:

score: 5
Accepted
time: 48ms
memory: 1368kb

input:

1000
787106265 727082581
227535146 533287459
837875354 738523208
652170865 583327908
506011496 84943...

output:

428205973
383213496
528352208
877162159
777685394
894739088
84479659
652708798
486341093
168396875
9...

result:

ok 1000 lines

Test #20:

score: 5
Accepted
time: 45ms
memory: 1368kb

input:

1000
756021044 519638624
79079358 955991362
303396062 299442290
396653454 370013814
118684193 153986...

output:

132509106
352701347
85904171
738200686
504144431
484013714
732464726
387380222
434892413
481760090
7...

result:

ok 1000 lines