QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#422137#4987. 图wtc#100 ✓798ms589884kbC++14968b2024-05-26 20:28:222024-05-26 20:28:22

Judging History

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

  • [2024-05-26 20:28:22]
  • 评测
  • 测评结果:100
  • 用时:798ms
  • 内存:589884kb
  • [2024-05-26 20:28:22]
  • 提交

answer

#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=(l);i<=(r);++i)
#define fd(i,l,r) for(int i=(l);i>=(r);--i)
#define fu(i,l,r) for(int i=(l);i<(r);++i)
#define ll long long
using namespace std;
const int N=3e7+3;
int n,T,mo,jc[N],jinv[N],iv[N],f[N],g[N];
ll ksm(ll x,int y){ll s=1;for(;y;y>>=1,x=x*x%mo)if(y&1)s=s*x%mo;return s;}
int main()
{
	scanf("%d%d",&T,&mo);
	n=3e7;
	jc[0]=1;fo(i,1,n) jc[i]=1ll*jc[i-1]*i%mo;
	jinv[n]=ksm(jc[n],mo-2);fd(i,n,1) jinv[i-1]=1ll*jinv[i]*i%mo;
	fo(i,1,n) iv[i]=1ll*jinv[i]*jc[i-1]%mo;
	f[0]=f[1]=1;f[2]=iv[2];
	fo(i,3,n) f[i]=1ll*(f[i-1]+((f[i-3]&1)?(mo+f[i-3]>>1):(f[i-3]>>1)))*iv[i]%mo;
	g[0]=1;
	for(int j=3;j<=n;j+=3) g[j]=1ll*g[j-3]*iv[6]%mo;
	for(int i=1,j=3;j<=n;++i,j+=3) g[j]=1ll*g[j]*jinv[i]%mo;
	while(T--)
	{
		scanf("%d",&n);
		if(n==1){printf("1\n");continue;}
		if(n%3==0) printf("%lld\n",1ll*g[n]*jc[n]%mo);
		else printf("%lld\n",(f[n-1]+g[n]+1ll*g[n-2]*(mo-iv[2]))%mo*jc[n]%mo);
	}
}

详细

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 796ms
memory: 589700kb

input:

8 998244353
1
2
3
4
5
6
7
8

output:

1
1
1
8
15
10
217
568

result:

ok 8 numbers

Subtask #2:

score: 15
Accepted

Dependency #1:

100%
Accepted

Test #2:

score: 15
Accepted
time: 795ms
memory: 589828kb

input:

200 321402013
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
9...

output:

1
1
1
8
15
10
217
568
280
12050
39831
15400
1123993
4448458
1401400
157764896
80087671
190590400
187957435
189964100
215150544
210537812
320589946
116147435
77322237
258401726
143880854
163578365
60466855
241862371
40755093
241051099
80785167
247356411
251514276
178274428
312164931
154916780
3015398...

result:

ok 200 numbers

Subtask #3:

score: 15
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #3:

score: 15
Accepted
time: 756ms
memory: 589720kb

input:

3000 621098477
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
...

output:

1
1
1
8
15
10
217
568
280
12050
39831
15400
1123993
4448458
1401400
157764896
101793220
190590400
608725310
26465057
188464334
181746076
546229079
477992250
553788308
95041077
72862000
377999633
453324334
390343581
378383862
26333899
448789829
467634276
16859121
578701622
560223528
54126595
7737831
...

result:

ok 3000 numbers

Subtask #4:

score: 20
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #4:

score: 20
Accepted
time: 794ms
memory: 589700kb

input:

100000 987654337
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
9...

output:

1
1
1
8
15
10
217
568
280
12050
39831
15400
1123993
4448458
1401400
157764896
722891697
190590400
425266236
890968006
656619868
590941449
783143242
198897988
819863574
553350865
444314195
349243413
573657492
638473836
972976899
210482843
633634816
467619442
823146932
716413123
883383200
284524945
92...

result:

ok 100000 numbers

Subtask #5:

score: 30
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #5:

score: 30
Accepted
time: 798ms
memory: 589884kb

input:

100000 987654439
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
9...

output:

1
1
1
8
15
10
217
568
280
12050
39831
15400
1123993
4448458
1401400
157764896
722891697
190590400
425263074
890951482
656616196
590100051
778293856
197951836
535903428
732607737
136808165
102841042
564792893
235466406
348855375
548639079
248113574
958091288
425942518
467065119
697029461
583676776
44...

result:

ok 100000 numbers