QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#113745#6554. Endless RoadxiaoyaowudiAC ✓362ms120812kbC++173.8kb2023-06-19 09:49:312023-06-19 09:49:33

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-19 09:49:33]
  • 评测
  • 测评结果:AC
  • 用时:362ms
  • 内存:120812kb
  • [2023-06-19 09:49:31]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <assert.h>
constexpr int p(998244353),N(2e6+10),_3((p+1)/3);
int inv[N],ifac[N],fac[N];
int fp(int a,int b){int ans(1),off(a);while(b){if(b&1) ans=1ll*ans*off%p;off=1ll*off*off%p;b>>=1;}return ans;}
void K(int a,int b,int c,int L,int deg,int coef,int res[])
{
	assert(a>=0);assert(b>=0);assert(c>=0);
	for(int i(0);i<=L && 3*i+a+b+c<=deg;++i) res[3*i+a+b+c]=(res[3*i+a+b+c]+1ll*coef*ifac[i+a]%p*ifac[i+b]%p*ifac[i+c])%p;
}
void J(int a,int b,int c,int L,int deg,int coef,int res[])
{
	assert(a>=0);assert(b>=0);assert(c>=0);
	for(int i(0);i<=L && 3*i+a+b+c<=deg;++i) res[3*i+a+b+c]=(res[3*i+a+b+c]+1ll*coef*ifac[i+a]%p*ifac[i+b]%p*ifac[i+c]%p*i)%p;
}
void F(int a,int b,int c,int deg,int coef,int res[])
{
	assert(a>=0);assert(b>=0);assert(c>=0);coef=1ll*coef*ifac[a]%p*ifac[b]%p;
	for(int i(0);i<=c && i+a+b<=deg;++i) res[i+a+b]=(res[i+a+b]+1ll*coef*ifac[i])%p;
}
void F(int a,int c,int deg,int coef,int res[])
{
	assert(a>=0);assert(c>=0);coef=1ll*coef*ifac[a]%p;
	for(int i(0);i<=c && i+a<=deg;++i) res[i+a]=(res[i+a]+1ll*coef*ifac[i])%p;
}
void FF(int a,int b,int c,int deg,int coef,int res[])
{
	assert(a>=0);assert(b>=0);assert(c>=0);
	int nd(deg-a);if(nd<0) return;static int T[N];
	std::fill(T,T+nd,0);F(b,c,nd-1,p-1,T);F(c,b,nd-1,p-1,T);coef=1ll*coef*ifac[a]%p;
	res[a]=(res[a]+coef)%p;
	for(int i(1),t(1);i<=nd;++i)
	{
		t=(2ll*t+T[i-1])*inv[i]%p;
		res[a+i]=(res[a+i]+1ll*t*coef)%p;
	}
}
void fg(int a,int b,int c,int L,int deg,int fx[],int gx[])
{
	assert(a>0);assert(b>0);assert(c>0);if(deg<0) return;
	int numf(0),numg(0);
	for(int i(0);i*2+a+b<=deg && i<=L;++i)
	{
		int j(deg-i*2-a-b);
		if(j<=i+c) numf=(numf+1ll*ifac[i+a]*ifac[i+b]%p*ifac[j])%p,
				   numg=(numg+1ll*ifac[i+a]*ifac[i+b]%p*ifac[j]%p*i)%p;
	}
	fx[deg]=numf,gx[deg]=numg;
	static int t1[N],t2[N];
	std::fill(t1,t1+deg,0);
	std::fill(t2,t2+deg,0);
	F(L+a,L+b,L+c,deg-2,p-2,t1+1);
	F(a-1,b-1,c-1,deg-2,2,t1+1);
	K(a-1,b-1,c,L,deg-2,2,t1+1);
	J(a,b,c,L,deg-1,p-1,t1);
	K(a,b,c,L,deg-1,1,t2);
	int x(1ll*(p-2)*a%p*b%p);
	for(int i(deg);i;--i)
	{
		fx[i-1]=(2*(p-gx[i])+1ll*(p+i-a-b)*fx[i]+t2[i-1])%p;
		gx[i-1]=(2ll*(p+i-1-a-b)*fx[i-1]+1ll*x*fx[i]+1ll*(p-i-a-b)*gx[i]+2*(i>1?t2[i-2]:0)+t1[i-1])%p*_3%p;
	}
}
void G(int a,int b,int c,int L,int deg,int coef,int res[],int fb[],int gb[],int fc[],int gc[])
{
	assert(a>0);assert(b>0);assert(c>0);if(deg<0) return;
	static int T[N];std::fill(T,T+deg,0);
	FF(a-1,b-1,c-1,deg-1,1,T);FF(a+L,b+L,c+L,deg-1,p-1,T);
	K(a-1,b,c,L,deg-1,p-1,T);
	for(int i(0);i<deg;++i)
	{
		T[i]=(T[i]+1ll*a*(fb[i+1]+fc[i+1])+p-fb[i]+p-fc[i]+gb[i+1]+gc[i+1])%p;
	}
	for(int i(1),t(0);i<=deg;++i)
	{
		t=(3ll*t+T[i-1])*inv[i]%p;
		res[i]=(res[i]+1ll*coef*t)%p;
	}
}
void H(int a,int b,int c,int L,int deg,int coef,int res[])
{
	assert(a>0);assert(b>0);assert(c>0);if(deg<0) return;
	static int fa[N],fb[N],fc[N],ga[N],gb[N],gc[N];
	fg(b,c,a,L,deg-1,fa,ga);
	fg(a,c,b,L,deg-1,fb,gb);
	fg(a,b,c,L,deg-1,fc,gc);
	static int T[N];std::fill(T,T+deg,0);
	G(a,b,c,L,deg-1,p-1,T,fb,gb,fc,gc);
	G(b,a,c,L,deg-1,p-1,T,fa,ga,fc,gc);
	G(c,a,b,L,deg-1,p-1,T,fa,ga,fb,gb);
	res[0]=(res[0]+1ll*(L+1)*coef)%p;
	for(int i(1),t(L+1);i<=deg;++i)
	{
		t=(3ll*t+T[i-1])*inv[i]%p;
		res[i]=(res[i]+1ll*coef*t)%p;
	}
}
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);int a,b,c,n;std::cin>>a>>b>>c>>n;
	fac[0]=1;for(int i(1);i<N;++i) fac[i]=1ll*fac[i-1]*i%p;ifac[N-1]=fp(fac[N-1],p-2);
	for(int i(N-1);i;--i) ifac[i-1]=1ll*ifac[i]*i%p,inv[i]=1ll*ifac[i]*fac[i-1]%p;
	static int fx[N];int x[3]={a,b,c};std::sort(x,x+3);int m(x[2]);
	FF(0,m-x[0],m-x[1],n,p-1,fx);
	H(m-a+1,m-b+1,m-c+1,n-1,n,p-1,fx);
	for(int i(1),j(_3);i<=n;++i,j=1ll*j*_3%p) std::cout<<(m+n+1+1ll*fac[i]*fx[i]%p*j)%p<<"\n";
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 17ms
memory: 50068kb

input:

0 0 0
5

output:

1
332748119
554580198
813384290
110916042

result:

ok 5 number(s): "1 332748119 554580198 813384290 110916042"

Test #2:

score: 0
Accepted
time: 17ms
memory: 50544kb

input:

111 222 456
10

output:

332748574
665496692
457
332748575
665496693
458
332748576
665496694
459
332748577

result:

ok 10 numbers

Test #3:

score: 0
Accepted
time: 18ms
memory: 51484kb

input:

0 0 0
100

output:

1
332748119
554580198
813384290
110916042
714792256
290298773
430883712
974509238
873989993
734317944
835462688
154757268
923205242
885314705
209291025
637685124
643859336
487195910
506723497
772211975
340846245
868174491
606646848
450657563
475687624
419817368
824343170
19675432
120063916
342859234...

result:

ok 100 numbers

Test #4:

score: 0
Accepted
time: 17ms
memory: 49788kb

input:

0 1 2
100

output:

332748120
110916042
887328317
665496239
743548267
288929440
817492294
724529743
614222297
317076859
988811171
967076519
751471247
133606165
14748157
362021315
549489057
937277754
415597831
485073323
916155749
240424973
413728850
410208012
903519447
196084907
817848817
766168642
161891353
619301293
7...

result:

ok 100 numbers

Test #5:

score: 0
Accepted
time: 17ms
memory: 50948kb

input:

1 13 99
400

output:

332748217
665496335
100
332748218
665496336
101
332748219
665496337
102
332748220
665496338
103
332748221
665496339
104
332748222
665496340
105
332748223
665496341
106
332748224
665496342
107
332748225
665496343
108
332748226
665496344
109
332748227
665496345
110
332748228
665496346
111
332748229
66...

result:

ok 400 numbers

Test #6:

score: 0
Accepted
time: 15ms
memory: 49756kb

input:

0 5 61
500

output:

332748179
665496297
62
332748180
665496298
63
332748181
665496299
64
332748182
665496300
65
332748183
665496301
66
332748184
665496302
67
332748185
665496303
68
332748186
665496304
69
332748187
665496305
70
332748188
665496306
71
332748189
665496307
72
332748190
665496308
73
332748191
665496309
74
3...

result:

ok 500 numbers

Test #7:

score: 0
Accepted
time: 17ms
memory: 50972kb

input:

0 2 5
500

output:

332748123
665496241
6
160212063
928408335
510761521
966293238
563709096
935610018
527751405
306730784
675447864
43719138
618247863
449591825
439345742
162772460
991789358
686798696
770662249
804237354
797676708
831486461
184129352
546170122
749993280
900200261
972640212
246249281
413426795
136984414...

result:

ok 500 numbers

Test #8:

score: 0
Accepted
time: 291ms
memory: 120628kb

input:

1 10 27
2000000

output:

332748145
665496263
28
332748146
665496264
29
332748147
665496265
30
332748148
665496266
31
332748149
665496267
32
332748150
665496268
179663022
592144721
59304515
413053926
598971324
468557114
87778038
628766814
661124777
49657764
822965780
808952900
131374221
542991233
872933331
856066802
52510600...

result:

ok 2000000 numbers

Test #9:

score: 0
Accepted
time: 336ms
memory: 120632kb

input:

1 2 3
2000000

output:

332748121
110916043
887328318
665496240
743548268
288929441
817492295
724529744
614222298
317076860
988811172
967076520
751471248
133606166
14748158
362021316
549489058
937277755
415597832
485073324
916155750
240424974
413728851
410208013
903519448
196084908
817848818
766168643
161891354
619301294
7...

result:

ok 2000000 numbers

Test #10:

score: 0
Accepted
time: 335ms
memory: 120724kb

input:

0 100 19999
2000000

output:

332768117
665516235
20000
332768118
665516236
20001
332768119
665516237
20002
332768120
665516238
20003
332768121
665516239
20004
332768122
665516240
20005
332768123
665516241
20006
332768124
665516242
20007
332768125
665516243
20008
332768126
665516244
20009
332768127
665516245
20010
332768128
6655...

result:

ok 2000000 numbers

Test #11:

score: 0
Accepted
time: 322ms
memory: 120572kb

input:

0 100000 299998
2000000

output:

333048116
665796234
299999
333048117
665796235
300000
333048118
665796236
300001
333048119
665796237
300002
333048120
665796238
300003
333048121
665796239
300004
333048122
665796240
300005
333048123
665796241
300006
333048124
665796242
300007
333048125
665796243
300008
333048126
665796244
300009
333...

result:

ok 2000000 numbers

Test #12:

score: 0
Accepted
time: 311ms
memory: 120752kb

input:

0 700000 855555
2000000

output:

333603673
666351791
855556
333603674
666351792
855557
333603675
666351793
855558
333603676
666351794
855559
333603677
666351795
855560
333603678
666351796
855561
333603679
666351797
855562
333603680
666351798
855563
333603681
666351799
855564
333603682
666351800
855565
333603683
666351801
855566
333...

result:

ok 2000000 numbers

Test #13:

score: 0
Accepted
time: 330ms
memory: 120636kb

input:

0 0 0
2000000

output:

1
332748119
554580198
813384290
110916042
714792256
290298773
430883712
974509238
873989993
734317944
835462688
154757268
923205242
885314705
209291025
637685124
643859336
487195910
506723497
772211975
340846245
868174491
606646848
450657563
475687624
419817368
824343170
19675432
120063916
342859234...

result:

ok 2000000 numbers

Test #14:

score: 0
Accepted
time: 331ms
memory: 120644kb

input:

2 3 4
2000000

output:

332748122
110916044
887328319
665496241
743548269
288929442
817492296
724529745
614222299
317076861
988811173
967076521
751471249
133606167
14748159
362021317
549489059
937277756
415597833
485073325
916155751
240424975
413728852
410208014
903519449
196084909
817848819
766168644
161891355
619301295
7...

result:

ok 2000000 numbers

Test #15:

score: 0
Accepted
time: 314ms
memory: 120640kb

input:

345 354 66876
2000000

output:

332814994
665563112
66877
332814995
665563113
66878
332814996
665563114
66879
332814997
665563115
66880
332814998
665563116
66881
332814999
665563117
66882
332815000
665563118
66883
332815001
665563119
66884
332815002
665563120
66885
332815003
665563121
66886
332815004
665563122
66887
332815005
6655...

result:

ok 2000000 numbers

Test #16:

score: 0
Accepted
time: 18ms
memory: 44996kb

input:

1000000 1000000 1000000
1

output:

1000001

result:

ok 1 number(s): "1000001"

Test #17:

score: 0
Accepted
time: 339ms
memory: 120652kb

input:

1000000 1000000 1000000
2000000

output:

1000001
333748119
555580198
814384290
111916042
715792256
291298773
431883712
975509238
874989993
735317944
836462688
155757268
924205242
886314705
210291025
638685124
644859336
488195910
507723497
773211975
341846245
869174491
607646848
451657563
476687624
420817368
825343170
20675432
121063916
343...

result:

ok 2000000 numbers

Test #18:

score: 0
Accepted
time: 362ms
memory: 120632kb

input:

0 5 6
2000000

output:

332748124
110916046
406692151
702468256
780520284
250588097
843966085
610875040
398881879
821245288
621559226
425057006
951494168
106603724
930151818
666086103
667717791
350655865
481819602
529636032
637307962
743456630
143921565
567351443
549064337
466547256
540711177
465397395
270202471
535482159
...

result:

ok 2000000 numbers

Test #19:

score: 0
Accepted
time: 346ms
memory: 120580kb

input:

0 5 7
2000000

output:

332748125
665496243
480636178
295776113
718900263
143780060
566904210
256978323
212246752
432709497
135090709
233560650
54196704
111597692
566089347
313956471
668686862
806073857
978650601
832909616
695025006
679208872
170965965
84033989
392810853
263850953
529617947
508523990
390319873
893015819
11...

result:

ok 2000000 numbers

Test #20:

score: 0
Accepted
time: 350ms
memory: 120644kb

input:

0 5 78
2000000

output:

332748196
665496314
79
332748197
665496315
80
332748198
665496316
81
332748199
665496317
82
332748200
665496318
83
332748201
665496319
84
332748202
665496320
85
332748203
665496321
86
332748204
665496322
87
332748205
665496323
88
332748206
665496324
89
332748207
665496325
90
332748208
665496326
91
3...

result:

ok 2000000 numbers

Test #21:

score: 0
Accepted
time: 316ms
memory: 120808kb

input:

0 5 89
2000000

output:

332748207
665496325
90
332748208
665496326
91
332748209
665496327
92
332748210
665496328
93
332748211
665496329
94
332748212
665496330
95
332748213
665496331
96
332748214
665496332
97
332748215
665496333
98
332748216
665496334
99
332748217
665496335
100
332748218
665496336
101
332748219
665496337
10...

result:

ok 2000000 numbers

Test #22:

score: 0
Accepted
time: 331ms
memory: 120640kb

input:

0 13 14
2000000

output:

332748132
110916054
406692159
702468264
780520292
250588105
110916056
829359866
617366705
681116802
948953989
234481060
229537183
992883705
3601765
198689084
86597949
666462415
882234461
826340534
577804891
360593551
881941231
451339878
411498169
258507277
548025960
241201304
807539500
422744226
627...

result:

ok 2000000 numbers

Test #23:

score: 0
Accepted
time: 333ms
memory: 120628kb

input:

0 13 81
2000000

output:

332748199
665496317
82
332748200
665496318
83
332748201
665496319
84
332748202
665496320
85
332748203
665496321
86
332748204
665496322
87
332748205
665496323
88
332748206
665496324
89
332748207
665496325
90
332748208
665496326
91
332748209
665496327
92
332748210
665496328
93
332748211
665496329
94
3...

result:

ok 2000000 numbers

Test #24:

score: 0
Accepted
time: 341ms
memory: 120812kb

input:

12 45 100
2000000

output:

332748218
665496336
101
332748219
665496337
102
332748220
665496338
103
332748221
665496339
104
332748222
665496340
105
332748223
665496341
106
332748224
665496342
107
332748225
665496343
108
332748226
665496344
109
332748227
665496345
110
332748228
665496346
111
332748229
665496347
112
332748230
66...

result:

ok 2000000 numbers

Test #25:

score: 0
Accepted
time: 323ms
memory: 120632kb

input:

12 45 1006
2000000

output:

332749124
665497242
1007
332749125
665497243
1008
332749126
665497244
1009
332749127
665497245
1010
332749128
665497246
1011
332749129
665497247
1012
332749130
665497248
1013
332749131
665497249
1014
332749132
665497250
1015
332749133
665497251
1016
332749134
665497252
1017
332749135
665497253
1018
...

result:

ok 2000000 numbers

Test #26:

score: 0
Accepted
time: 336ms
memory: 120636kb

input:

12 45 100654
2000000

output:

332848772
665596890
100655
332848773
665596891
100656
332848774
665596892
100657
332848775
665596893
100658
332848776
665596894
100659
332848777
665596895
100660
332848778
665596896
100661
332848779
665596897
100662
332848780
665596898
100663
332848781
665596899
100664
332848782
665596900
100665
332...

result:

ok 2000000 numbers

Test #27:

score: 0
Accepted
time: 337ms
memory: 120584kb

input:

12 45 509999
2000000

output:

333258117
666006235
510000
333258118
666006236
510001
333258119
666006237
510002
333258120
666006238
510003
333258121
666006239
510004
333258122
666006240
510005
333258123
666006241
510006
333258124
666006242
510007
333258125
666006243
510008
333258126
666006244
510009
333258127
666006245
510010
333...

result:

ok 2000000 numbers

Test #28:

score: 0
Accepted
time: 345ms
memory: 120776kb

input:

123 435 10340
2000000

output:

332758458
665506576
10341
332758459
665506577
10342
332758460
665506578
10343
332758461
665506579
10344
332758462
665506580
10345
332758463
665506581
10346
332758464
665506582
10347
332758465
665506583
10348
332758466
665506584
10349
332758467
665506585
10350
332758468
665506586
10351
332758469
6655...

result:

ok 2000000 numbers

Test #29:

score: 0
Accepted
time: 307ms
memory: 120808kb

input:

12 45 1002
2000000

output:

332749120
665497238
1003
332749121
665497239
1004
332749122
665497240
1005
332749123
665497241
1006
332749124
665497242
1007
332749125
665497243
1008
332749126
665497244
1009
332749127
665497245
1010
332749128
665497246
1011
332749129
665497247
1012
332749130
665497248
1013
332749131
665497249
1014
...

result:

ok 2000000 numbers

Test #30:

score: 0
Accepted
time: 339ms
memory: 120636kb

input:

12 45 10012
2000000

output:

332758130
665506248
10013
332758131
665506249
10014
332758132
665506250
10015
332758133
665506251
10016
332758134
665506252
10017
332758135
665506253
10018
332758136
665506254
10019
332758137
665506255
10020
332758138
665506256
10021
332758139
665506257
10022
332758140
665506258
10023
332758141
6655...

result:

ok 2000000 numbers