QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#371397#7649. 序列hcawa#100 ✓91ms8036kbC++141.8kb2024-03-30 10:30:502024-07-04 03:32:58

Judging History

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

  • [2024-07-04 03:32:58]
  • 评测
  • 测评结果:100
  • 用时:91ms
  • 内存:8036kb
  • [2024-03-30 10:30:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 7;

int f[N][N][N], s[N][N];
int fac[N], inv[N], invfac[N];

int Mod, T, n, m;

template <class T = int>
inline T read() {
	char c = getchar();
	bool sign = (c == '-');
	
	while (c < '0' || c > '9')
		c = getchar(), sign |= (c == '-');
	
	T x = 0;
	
	while ('0' <= c && c <= '9')
		x = (x << 1) + (x << 3) + (c & 15), c = getchar();
	
	return sign ? (~x + 1) : x;
}

inline int add(int x, int y) {
	x += y;
	
	if (x >= Mod)
		x -= Mod;
	
	return x;
}

inline void prework() {
	fac[0] = fac[1] = 1;
	inv[0] = inv[1] = 1;
	invfac[0] = invfac[1] = 1;

	for (int i = 2; i < N; ++i) {
		fac[i] = 1ll * fac[i - 1] * i % Mod;
		inv[i] = 1ll * (Mod - Mod / i) * inv[Mod % i] % Mod;
		invfac[i] = 1ll * invfac[i - 1] * inv[i] % Mod;
	}
}

signed main() {
	Mod = read(), T = read();
	prework();
	f[1][1][0] = 1;

	for (int i = 1; i + 1 < N; ++i)
		for (int j = 1; j <= i; ++j)
			for (int k = 0; k <= j; ++k) {
				if (k)
					f[i + 1][j][k] = add(f[i + 1][j][k], f[i][j][k]); // 放一个 k

				for (int x = k; x < j; ++x) { // 放一个恰好比 x 大的数
					f[i + 1][j][x] = add(f[i + 1][j][x], f[i][j][k]); // 放一个出现过的数
					f[i + 1][j + 1][x] = add(f[i + 1][j + 1][x], f[i][j][k]); // 放一个没出现的数
				}

				f[i + 1][j + 1][j] = add(f[i + 1][j + 1][j], f[i][j][k]); // 放一个比所有数都大的数
			}

	for (int i = 1; i < N; ++i)
		for (int j = 1; j <= i; ++j)
			for (int k = 0; k <= j; ++k)
				s[i][j] = add(s[i][j], f[i][j][k]);

	while (T--) {
		n = read(), m = read() + 1;
		int ans = 0, mul = 1;

		for (int i = 1; i <= min(n, m); ++i) {
			mul = 1ll * mul * (m - i + 1) % Mod;
			ans = add(ans, 1ll * mul * invfac[i] % Mod * s[n][i] % Mod);
		}

		printf("%d\n", ans);
	}

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 10ms
memory: 6520kb

input:

524522849 10
2 0
6 6
8 4
1 0
12 6
8 6
6 3
13 9
13 4
6 3

output:

1
42168
80720
1
152431216
779562
2168
121730169
20312320
2168

result:

ok 10 lines

Test #2:

score: 5
Accepted
time: 10ms
memory: 6596kb

input:

227468749 544
1 0
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
2 0
2 1
2 2
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 12
2 13
2 14
2 15
2 16
3 0
3 1
3 2
3 3
3 4
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
3 13
3 14
3 15
3 16
4 0
4 1
4 2
4 3
4 4
4 5
4 6
4 7
4 8
4 9
4 10
4 11
4 12
4 13
4...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
1
4
9
16
25
36
49
64
81
100
121
144
169
196
225
256
289
1
8
26
60
115
196
308
456
645
880
1166
1508
1911
2380
2920
3536
4233
1
16
72
210
485
966
1736
2892
4545
6820
9856
13806
18837
25130
32880
42296
53601
1
32
192
692
1897
4368
8904
16584
28809
47344
74360
...

result:

ok 544 lines

Test #3:

score: 5
Accepted
time: 10ms
memory: 6532kb

input:

264655177 10
11 6
6 3
13 9
3 3
14 11
5 3
12 12
17 9
15 1
3 0

output:

43100708
2168
199672651
60
122403246
692
233439700
36637531
32768
1

result:

ok 10 lines

Test #4:

score: 5
Accepted
time: 10ms
memory: 6580kb

input:

480867533 684
1 0
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
2 0
2 1
2 2
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 12
2 13
2 14
2 15
2 16
2 17
2 18
3 0
3 1
3 2
3 3
3 4
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
3 13
3 14
3 15
3 16
3 17
3 18
4 0
4 1
4 2
4 3
4 4
4 5
4 6
4 7...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1
4
9
16
25
36
49
64
81
100
121
144
169
196
225
256
289
324
361
1
8
26
60
115
196
308
456
645
880
1166
1508
1911
2380
2920
3536
4233
5016
5890
1
16
72
210
485
966
1736
2892
4545
6820
9856
13806
18837
25130
32880
42296
53601
67032
82840
1
32
192
692
189...

result:

ok 684 lines

Test #5:

score: 5
Accepted
time: 21ms
memory: 6576kb

input:

887376619 80000
3 86064667
9 562451738
13 221525596
4 603268314
13 448831536
11 228885126
5 118994448
1 391362768
8 825243129
6 840482237
10 773261556
2 362011603
1 622070752
17 860378839
10 807811468
8 48463804
14 851836228
18 62643253
1 449926370
2 182952593
15 428270854
6 71161534
5 615732693
12 ...

output:

465434475
734078808
38303678
65753012
556583023
381929546
76575886
391362769
584735247
71024747
204979444
879301064
622070753
707639232
454236199
189385067
15057214
520013758
449926371
805505016
802856839
216936592
545210877
506484086
361480956
857131574
574061754
804068585
589500242
767169164
79353...

result:

ok 80000 lines

Test #6:

score: 5
Accepted
time: 20ms
memory: 6580kb

input:

520372459 80000
16 73222046
5 919013858
14 162396817
14 926507113
18 935346003
5 698535409
11 258567597
5 798394937
16 388896427
15 404111176
5 850571322
5 181043723
12 570125320
7 109863152
6 934874731
18 377964360
3 28198540
13 179568270
11 132674574
1 18069792
15 239015051
16 182185910
14 3659399...

output:

516390052
485408631
469804556
256399625
423104612
317769001
163306754
273375357
361133763
440924753
326587375
478997315
297638733
117551707
15130640
199574845
473177794
126091533
23341749
18069793
433662244
329622741
176508368
410495528
110476055
89428561
278170884
472412735
360556241
35262939
44464...

result:

ok 80000 lines

Test #7:

score: 5
Accepted
time: 10ms
memory: 6584kb

input:

952294969 50
11 1
5 2
19 16
15 12
19 11
14 3
5 1
13 8
9 7
16 4
9 0
1 1
4 1
17 10
7 4
16 9
16 12
13 11
15 15
9 4
14 5
15 10
11 9
18 9
13 3
8 0
9 3
20 14
19 18
11 11
5 0
20 12
5 2
2 0
7 2
5 0
11 3
2 0
12 8
19 1
16 6
5 4
1 1
9 1
19 17
20 18
15 4
11 8
19 18
5 5

output:

2048
192
131765410
236829293
628222726
6768640
32
127554662
8559848
429056000
1
2
16
818650964
24250
539164726
927068340
557885583
35149418
258560
353537664
116883611
136711391
811617069
2657280
1
53120
809193261
905397922
327380106
1
170540940
192
1
1248
1
390656
1
751662260
524288
2269637
1897
2
5...

result:

ok 50 lines

Test #8:

score: 5
Accepted
time: 10ms
memory: 6512kb

input:

783724693 840
1 0
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
2 0
2 1
2 2
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 12
2 13
2 14
2 15
2 16
2 17
2 18
2 19
2 20
3 0
3 1
3 2
3 3
3 4
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
3 13
3 14
3 15
3 16
3 17
3 18
3 19
3 20
4...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
1
4
9
16
25
36
49
64
81
100
121
144
169
196
225
256
289
324
361
400
441
1
8
26
60
115
196
308
456
645
880
1166
1508
1911
2380
2920
3536
4233
5016
5890
6860
7931
1
16
72
210
485
966
1736
2892
4545
6820
9856
13806
18837
25130
32880
42296
53601
6703...

result:

ok 840 lines

Test #9:

score: 5
Accepted
time: 22ms
memory: 6516kb

input:

212783423 80000
8 19974544
13 201687803
9 174317697
15 200496317
1 18082075
18 15231892
11 2288827
13 169041511
6 138681763
18 114930625
3 106033333
4 25454931
12 78364940
11 66424466
18 206727112
9 37616009
4 144638527
7 87017746
13 50574132
10 110396114
13 82283585
19 102697380
19 179757066
13 246...

output:

81320539
84229486
118058073
21051987
18082076
91298326
66900269
123113923
204502140
134096558
35592817
18782576
89613406
183476668
166575838
166725448
166079161
39357360
82518753
24937998
162384422
63464016
125353890
100121615
197327223
199742241
196151579
47187698
174827940
163768498
23604402
51528...

result:

ok 80000 lines

Test #10:

score: 5
Accepted
time: 21ms
memory: 6604kb

input:

106024679 80000
2 831354172
11 745444414
2 300269201
2 142136821
2 453492948
9 63555154
19 904991583
8 492468020
7 478542603
18 412373612
11 269432982
12 226491229
3 706299655
2 322453386
1 58328554
2 762334373
16 389359295
14 977607830
11 341515712
16 397850261
5 10645808
6 479990005
2 143746316
11...

output:

50956189
40220751
55562089
72251731
60490292
20026534
99231894
88271425
8609127
56518882
60389839
97804983
67944924
8262869
58328555
81863208
14380608
16244748
64235184
50543498
71184434
105000853
62762151
59733725
47279078
21993240
83720776
88940159
103210250
78483238
73423550
25352950
81277108
978...

result:

ok 80000 lines

Test #11:

score: 5
Accepted
time: 10ms
memory: 8036kb

input:

600404131 100
12 10
3 0
18 9
3 0
4 1
12 6
20 13
6 3
10 1
23 17
11 5
2 1
15 0
4 4
23 10
16 15
8 8
25 5
2 0
2 2
15 7
6 2
2 1
1 1
22 11
18 3
6 0
8 0
1 0
20 13
21 10
4 0
16 13
9 6
17 8
8 0
15 7
16 11
17 4
24 23
19 0
20 7
14 1
22 22
13 10
11 6
7 0
3 2
23 16
25 5
18 16
16 9
1 1
12 4
3 2
16 11
12 4
6 6
7 6...

output:

540046116
1
316823993
1
16
152431216
88546859
2168
1024
181316512
11270448
4
1
485
550400666
143022779
4492125
356418570
1
9
156818082
496
4
2
401055983
252313600
1
1
1
88546859
110489355
1
324641872
3097094
113711493
1
156818082
157236878
548933469
87076233
1
323687234
16384
85774370
545782662
4310...

result:

ok 100 lines

Test #12:

score: 5
Accepted
time: 7ms
memory: 6672kb

input:

496289723 100
43 40
37 37
33 33
3 1
7 1
1 0
27 20
4 4
11 3
43 5
49 14
42 10
14 2
7 2
13 4
5 2
16 1
37 34
8 6
13 5
36 33
34 16
21 2
26 26
46 37
20 6
49 33
2 0
27 23
13 12
17 16
2 0
34 22
13 2
48 48
47 11
9 0
8 8
11 3
43 38
2 0
44 4
18 5
24 2
6 5
1 0
29 4
15 2
16 2
40 35
50 8
11 4
31 1
28 19
35 28
42 ...

output:

353365404
172335259
421815053
8
128
1
448248955
485
390656
415584144
414510038
158501726
503808
1248
20312320
192
65536
441602416
779562
114934848
481243051
474116804
134217728
75080423
212761592
127003739
315199204
1
306623071
346860396
336253351
1
164397551
221184
490211905
338770953
1
4492125
390...

result:

ok 100 lines

Test #13:

score: 5
Accepted
time: 7ms
memory: 6556kb

input:

621400763 500
40 36
39 5
7 7
36 36
60 57
51 34
2 0
9 5
65 0
36 14
63 5
35 30
49 12
20 1
7 2
16 5
67 60
67 14
26 25
31 15
45 21
61 40
39 22
66 39
19 0
41 7
15 9
21 13
7 2
53 47
7 1
45 11
43 37
12 8
50 23
54 18
17 9
8 6
57 15
6 6
5 2
9 6
29 3
67 61
35 12
59 31
58 23
11 5
69 51
47 24
26 18
38 21
13 6
8...

output:

466132494
524488958
427416
238204824
466994491
321875214
1
978812
1
248929058
256571528
324309574
96778035
1048576
1248
34223705
142187442
45776825
195063976
506301839
20075720
303408478
566938169
260222413
1
571600642
134071792
590713520
1248
349499045
128
462919425
400768962
461155703
201608678
13...

result:

ok 500 lines

Test #14:

score: 5
Accepted
time: 7ms
memory: 6512kb

input:

223562309 1000
13 1
29 0
57 8
84 2
91 45
88 78
25 18
16 2
65 54
78 53
70 14
87 18
75 56
69 47
31 19
74 40
64 59
13 9
89 15
96 4
62 12
93 54
6 3
88 69
86 2
84 43
2 0
46 6
62 24
43 16
62 53
84 20
73 15
58 17
100 57
9 0
45 43
70 13
17 6
38 15
76 49
62 52
29 3
94 92
92 15
1 0
68 4
37 1
64 21
28 12
20 2
...

output:

8192
1
97753014
46765647
205581911
95900844
187387517
2555904
109285616
150385779
137356068
148865340
131587824
170413212
46092816
32520260
9358176
10388852
5091598
219769745
187038132
21038380
2168
18767801
181608309
104871713
1
71061713
45945073
183510675
128155606
59224375
101127434
168615825
163...

result:

ok 1000 lines

Test #15:

score: 5
Accepted
time: 7ms
memory: 6540kb

input:

452850613 1000
63 71
77 1
50 91
13 2
62 69
44 86
85 19
81 1
8 32
71 38
55 77
40 14
81 24
78 29
38 66
52 70
96 45
77 32
6 47
31 21
59 36
100 74
6 70
68 15
49 18
55 83
10 6
50 24
82 80
91 6
59 85
13 4
15 66
28 95
61 44
55 45
21 19
78 14
32 94
78 27
47 36
2 90
30 6
88 76
37 24
76 98
58 35
4 83
44 88
33...

output:

401763047
438272338
450078815
221184
369321640
262417950
50853059
219598213
235348873
326084825
228667545
263362189
451230703
377048900
382169316
258779325
406807711
71033697
241246295
203171141
170260802
387680425
422786069
36702217
400656617
268071322
11778074
176023954
427862276
435071118
3906633...

result:

ok 1000 lines

Test #16:

score: 5
Accepted
time: 14ms
memory: 6536kb

input:

761474531 20200
1 0
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
1
4
...

result:

ok 20200 lines

Test #17:

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

input:

958530557 80000
41 40257119
26 551269419
13 343471048
6 707178986
39 480950278
28 320336393
3 494144556
22 451754444
30 951880952
24 202939355
6 674633244
52 821067810
12 158631818
24 153528712
47 955075270
65 879099472
61 893724013
3 48434989
42 672224069
52 379892187
2 256361346
42 279740788
21 32...

output:

800786630
221985103
829053408
7735057
636020347
63338004
811912070
113857201
89817258
746486740
669300108
406206633
833385792
189985041
839956400
372916314
678775359
383942235
724392594
389256772
616144619
339852399
847755796
442496480
517970857
938478009
618674103
539558629
704214744
933146055
3280...

result:

ok 80000 lines

Test #18:

score: 5
Accepted
time: 40ms
memory: 6508kb

input:

624716887 80000
6 456329391
43 632992788
43 217134997
44 404182336
5 236226834
22 633995373
55 420812010
35 798920287
33 416517710
48 977259453
28 550396683
60 995420413
38 260416463
5 313697757
49 566596131
58 171411729
7 393254620
27 177046578
16 89947502
37 632303990
2 676866438
67 197185794
22 2...

output:

198036938
405987478
429981446
271602301
212615
432885088
474599822
177267553
60742922
341503973
114394052
561456180
505006655
354428455
314172
173776879
411984257
354375007
107314101
68822645
122641813
567461267
473565996
427816534
391964972
311090211
134415876
395692164
383627207
260098163
32303097...

result:

ok 80000 lines

Test #19:

score: 5
Accepted
time: 55ms
memory: 6536kb

input:

456219923 80000
20 841521091
29 986403028
41 875639318
16 284809348
17 159910772
99 122339664
48 274573518
12 569154004
7 359437972
70 726098399
36 813532210
93 639270654
34 805505688
38 83215311
11 721526199
97 946514202
41 75562523
4 854142384
72 483275498
68 536263310
23 8259165
39 389669476
2 57...

output:

237992251
324653345
428249523
47117297
54240937
276551263
188687397
187772321
38762550
412166893
191264900
46123087
221215306
95322137
455568574
371393566
17170403
99278925
66808670
365907108
419875860
84684582
360215167
131124337
455989654
390901918
163316405
374216603
76113407
231839564
368698301
...

result:

ok 80000 lines

Test #20:

score: 5
Accepted
time: 91ms
memory: 6604kb

input:

812178671 80000
100 183369566
100 358019720
100 913771866
100 194917298
100 139816752
100 227312067
100 386470983
100 940332122
100 764269079
100 510657776
100 923887110
100 157149772
100 34844910
100 680136044
100 560852766
100 415024759
100 232435279
100 874155651
100 810722501
100 972959473
100 7...

output:

672344952
798304820
526251616
801609840
101796789
260016583
91433259
746535002
460553761
279892005
532588362
618657467
239064215
243121549
104944419
557085383
37060004
371930005
440716780
699223903
431280058
723868443
489966974
11834885
445083382
125283756
748559409
230581439
578455520
808746960
786...

result:

ok 80000 lines