QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#396276#7068. Lucky SequencezhouhuanyiAC ✓366ms71860kbC++144.3kb2024-04-22 16:42:402024-04-22 16:42:41

Judging History

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

  • [2024-04-22 16:42:41]
  • 评测
  • 测评结果:AC
  • 用时:366ms
  • 内存:71860kb
  • [2024-04-22 16:42:40]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#define N 100000
#define K 18
#define M 262144
#define g 3
#define mod 998244353
using namespace std;
const double eps=1e-8;
double ds=(sqrt(5)+1)/2;
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
int fast_pow(int a,int b)
{
	int res=1,mul=a;
	while (b)
	{
		if (b&1) res=1ll*res*mul%mod;
		mul=1ll*mul*mul%mod,b>>=1;
	}
	return res;
}
int MD(int x)
{
	return x>=mod?x-mod:x;
}
int MD2(int x)
{
	return x<0?x+mod:x;
}
void Adder(int &x,int d)
{
	x+=d;
	if (x>=mod) x-=mod;
	return;
}
void Adder2(int &x,int d)
{
	x+=d;
	if (x<0) x+=mod;
	return;
}
int ST,n,length,F[N+1],fac[N+1],invfac[N+1],inv[N+1],tB[N+1],a[N+1],A[M+1],B[M+1],num[M+1],rev[M+1],wn[K+1][M+1],wn2[K+1][M+1];
void NTT(int limit,int *s,int type)
{
	int s1,s2;
	for (int i=1;i<limit;++i) rev[i]=(rev[i>>1]>>1)|((i&1)?(limit>>1):0);
	for (int i=1;i<limit;++i)
		if (rev[i]>i)
			swap(s[i],s[rev[i]]);
	if (type==1)
	{
		for (int i=2;i<=limit;i<<=1)
			for (int j=0;j+i-1<limit;j+=i)
				for (int k=j;k<j+(i>>1);++k)
					s1=s[k],s2=1ll*s[k+(i>>1)]*wn[num[i]][k-j]%mod,s[k]=MD(s1+s2),s[k+(i>>1)]=MD2(s1-s2);
	}
	else
	{
		for (int i=2;i<=limit;i<<=1)
			for (int j=0;j+i-1<limit;j+=i)
				for (int k=j;k<j+(i>>1);++k)
					s1=s[k],s2=1ll*s[k+(i>>1)]*wn2[num[i]][k-j]%mod,s[k]=MD(s1+s2),s[k+(i>>1)]=MD2(s1-s2);
		s1=fast_pow(limit,mod-2);
		for (int i=0;i<=limit;++i) s[i]=1ll*s[i]*s1%mod;
	}
	return;
}
vector<int>operator * (vector<int>a,vector<int>b)
{
	int limit=1;
	vector<int>c(a.size()+b.size()-1);
	while (limit<=a.size()+b.size()) limit<<=1;
	for (int i=0;i<=limit;++i) A[i]=B[i]=0;
	for (int i=0;i<a.size();++i) A[i]=a[i];
	for (int i=0;i<b.size();++i) B[i]=b[i];
	NTT(limit,A,1),NTT(limit,B,1);
	for (int i=0;i<=limit;++i) A[i]=1ll*A[i]*B[i]%mod;
	NTT(limit,A,-1);
	for (int i=0;i<c.size();++i) c[i]=A[i];
	return c;
}
struct seg
{
	struct node
	{
		vector<int>data;
	};
	node tree[(N<<2)+1];
	void push_up(int k)
	{
		tree[k].data=tree[k<<1].data*tree[k<<1|1].data;
		return;
	}
	void build(int k,int l,int r)
	{
		if (l==r)
		{
			tree[k].data={a[l],1};
			return;
		}
		int mid=(l+r)>>1;
		build(k<<1,l,mid),build(k<<1|1,mid+1,r),push_up(k);
		return;
	}
	void solve(int k,int l,int r,vector<int>p)
	{
		if (l==r)
		{
			F[l]=MD(1ll*p[0]*a[l]%mod+p[1]);
			return;
		}
		int mid=(l+r)>>1,limit=1;
		vector<int>p1(mid-l+2);
		vector<int>p2(r-mid+1);
		for (int i=0;i<=mid-l+1;++i) p1[i]=p[i];
		while (limit<=r-l+1) limit<<=1;
		for (int i=0;i<=limit;++i) A[i]=B[i]=0;
		for (int i=0;i<=r-l+1;++i) A[i]=p[i];
		for (int i=0;i<=mid-l+1;++i) B[mid-l+1-i]=tree[k<<1].data[i];
		NTT(limit,A,1),NTT(limit,B,1);
		for (int i=0;i<=limit;++i) A[i]=1ll*A[i]*B[i]%mod;
		NTT(limit,A,-1);
		for (int i=0;i<=r-mid;++i) p2[i]=A[mid-l+1+i];
		solve(k<<1,l,mid,p1),solve(k<<1|1,mid+1,r,p2);
		return;
	}
};
seg T;
void solve(int l,int r)
{
	if (l==r)
	{
		if (l) tB[l]=1ll*tB[l]*inv[l]%mod;
		return;
	}
	int mid=(l+r)>>1,limit=1;
	solve(l,mid);
	while (limit<=r-l) limit<<=1;
	for (int i=0;i<=limit;++i) A[i]=B[i]=0;
	for (int i=l;i<=mid;++i) A[i-l]=tB[i];
	for (int i=1;i<=r-l;++i) B[i]=invfac[i-1];
	NTT(limit,A,1),NTT(limit,B,1);
	for (int i=0;i<=limit;++i) A[i]=1ll*A[i]*B[i]%mod;
	NTT(limit,A,-1);
	for (int i=mid+1;i<=r;++i) Adder(tB[i],A[i-l]);
	solve(mid+1,r);
	return;
}
int main()
{
	vector<int>p;
	fac[0]=1;
	for (int i=1;i<=N;++i) fac[i]=1ll*fac[i-1]*i%mod;
	invfac[N]=fast_pow(fac[N],mod-2);
	for (int i=N-1;i>=0;--i) invfac[i]=1ll*invfac[i+1]*(i+1)%mod;
	for (int i=1;i<=N;++i) inv[i]=1ll*fac[i-1]*invfac[i]%mod;
	for (int i=2,w;i<=M;i<<=1)
	{
		num[i]=++length,w=fast_pow(g,(mod-1)/i);
		for (int j=0,res=1;j<(i>>1);++j,res=1ll*res*w%mod) wn[num[i]][j]=res;
		w=fast_pow(g,(mod-1)/i*(i-1));
		for (int j=0,res=1;j<(i>>1);++j,res=1ll*res*w%mod) wn2[num[i]][j]=res;
	}
	tB[0]=1,solve(0,N);
	for (int i=0;i<=N;++i) tB[i]=1ll*tB[i]*fac[i]%mod;
	p.resize(N+1);
	for (int i=0;i<=N;++i) p[i]=tB[i];
	for (int i=1;i<=N;++i) a[i]=floor(ds*i-eps)-i+1;
	T.build(1,1,N),T.solve(1,1,N,p),ST=read();
	while (ST--) n=read(),printf("%d\n",F[n]);
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 360ms
memory: 71772kb

input:

5
1
2
3
4
5

output:

2
7
27
141
919

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 361ms
memory: 71548kb

input:

1
100000

output:

757797613

result:

ok single line: '757797613'

Test #3:

score: 0
Accepted
time: 352ms
memory: 71604kb

input:

1000
22568
59901
32625
77159
20665
98646
44928
96592
11443
88137
53705
90354
41583
60817
91696
66427
88639
6813
93000
13395
94112
62534
71965
21812
32169
82345
98958
16560
82042
53679
34636
20843
58907
12943
49049
68406
95730
52351
31702
42849
75524
28355
87441
3977
19409
26840
73924
75239
13883
944...

output:

512283284
732335762
162105871
244853136
93946059
351609654
670047232
235011092
817841037
663728573
178057637
545578765
823475841
179802724
754488058
21427077
368516001
755976516
332817809
895573832
392503381
281753219
807154049
697506532
558401292
682309547
498678317
420405486
355816470
941769776
77...

result:

ok 1000 lines

Test #4:

score: 0
Accepted
time: 361ms
memory: 71808kb

input:

1000
9036
1921
59088
29263
53830
77915
67459
59238
72694
29746
32438
7567
25267
26295
39332
67958
7573
70442
27833
2712
27455
71660
79485
61606
11385
52165
96451
52784
25154
17847
23378
64935
92207
633
33324
34080
62726
79312
36738
25534
61256
83134
45722
87124
92548
29778
90065
90708
14206
55949
11...

output:

887375738
185864495
684204616
940533366
214730721
427877381
537051774
241528143
914147368
257911534
646344438
595659017
689901164
259655462
989375542
601886315
831005775
362780664
447990250
770016429
392018535
361158668
339978840
93002231
731735636
791569625
280701332
89862683
787031441
263606571
79...

result:

ok 1000 lines

Test #5:

score: 0
Accepted
time: 355ms
memory: 71860kb

input:

1000
18753
21822
39143
6714
68147
95863
39060
58705
95632
50357
4795
79518
59901
62662
99291
38704
84028
4237
48888
42300
9765
67389
84274
18166
71932
38845
83579
79872
21597
4398
99385
72717
89530
18304
91849
75851
41785
49049
62801
15609
86223
97168
20923
65866
138
34515
60476
68228
232
17730
6453...

output:

847853379
490142143
673596645
633463716
742615413
940771896
298370451
986022532
989886624
30063041
119774969
835085555
732335762
144917760
225716898
631456583
996772590
499376995
623307593
441444421
371565727
906287178
94408606
836398569
72091648
638263600
1668580
685924314
776387400
462260232
62128...

result:

ok 1000 lines

Test #6:

score: 0
Accepted
time: 351ms
memory: 71808kb

input:

1000
9513
14175
55601
54182
68054
33647
72330
49716
77434
83984
61145
23443
29675
81854
56051
66132
21694
31969
52809
70725
96685
73465
73760
35841
62259
68786
50070
51114
28051
24156
59943
45754
36177
64459
50052
60986
50871
33936
48815
71534
67001
7951
14017
59979
3199
30048
71211
471
93958
74982
...

output:

248228171
617478841
724297497
536828530
837112925
567900010
953779955
766853711
779353623
744687738
169545852
681986171
540328169
325854664
499398139
421957212
468535573
62035110
623804049
17215982
986909702
1381863
287855436
730040477
487382960
491162791
417105311
303894823
726777088
198921466
8115...

result:

ok 1000 lines

Test #7:

score: 0
Accepted
time: 364ms
memory: 71840kb

input:

1000
595
308
350
695
485
649
265
445
93
486
884
805
317
960
567
921
456
791
871
18
55
529
431
69
959
738
915
375
45
663
999
33
289
277
806
298
154
197
12
326
824
30
346
722
76
361
293
818
719
957
787
809
661
507
751
212
962
631
569
536
561
128
603
112
939
878
890
58
754
664
408
438
637
10
463
544
62...

output:

352785038
829829846
39575634
126040755
619499866
381691595
345092526
742931755
847329892
173347173
644103387
291336371
812680979
970778935
286583786
221641110
87302280
432217395
946634817
72328049
290512351
311359326
291312676
41951599
182614473
988877478
64733444
582927217
28337171
662340124
699540...

result:

ok 1000 lines

Test #8:

score: 0
Accepted
time: 358ms
memory: 71712kb

input:

5000
3108
479
4147
4591
3406
2597
804
1866
2588
483
4617
1053
1688
3205
1701
62
221
2882
2522
737
3390
674
1342
316
3408
3629
742
2702
3196
3925
1477
668
3481
2949
4364
3980
1640
2074
866
4618
1417
194
1974
3013
4861
3433
730
4910
3962
1310
2233
1956
1796
1544
1824
2481
2106
4387
3580
2009
1104
865
...

output:

811145023
490241791
702731360
665593153
227447720
753826493
309609946
814480975
740657570
190657935
848212018
272405848
411866278
896971116
872110711
266006587
212101945
156873600
402193881
175850816
466147152
338801852
293987585
734927745
444768928
955370403
850280395
810632080
387790567
522296108
...

result:

ok 5000 lines

Test #9:

score: 0
Accepted
time: 366ms
memory: 71768kb

input:

10000
4506
1218
6756
2702
8980
3053
4978
5425
752
848
1366
9354
9736
5621
7171
8691
2329
9621
549
6984
1256
2150
8848
1206
4098
7273
5851
628
7691
9884
7692
9437
269
9422
6310
738
6704
3517
7253
5823
6252
994
3179
871
6821
1972
47
8803
1451
1352
8929
6025
4306
1215
8455
3232
9232
7015
7389
1949
8612...

output:

824678440
653433658
352726779
810632080
448760348
974135082
106267916
317116073
449569904
639850813
595301743
685365656
434898268
165533795
459795155
480195116
4712339
826100316
309080081
541007291
484784260
850485526
291559803
716616440
409459581
51505304
978154883
744447406
864704215
857749367
335...

result:

ok 10000 lines

Test #10:

score: 0
Accepted
time: 354ms
memory: 71748kb

input:

50000
30139
9357
22016
23146
17573
40473
17256
44159
10840
33027
34006
25292
2522
26127
23709
6764
10182
1973
19232
40340
23057
6887
42462
28416
46337
37357
23724
44037
32611
12567
48215
6369
35321
16233
45712
2797
16235
28244
36019
11022
17669
49532
7218
40406
25222
16749
34921
2192
46664
18305
311...

output:

330862674
251042768
174291998
127471841
583159196
859026054
640820458
555388145
642223703
581692140
122867752
304841037
402193881
580968810
8043081
896581221
517973455
645552913
618894682
406913577
156838272
630874756
156497658
582281930
311207160
957873093
809717564
97471206
82484740
816302156
7650...

result:

ok 50000 lines

Test #11:

score: 0
Accepted
time: 359ms
memory: 71568kb

input:

100000
72992
57376
9369
55254
56984
8840
53487
9703
41014
48
35475
65765
56966
13931
95666
28913
24522
84969
13694
10049
4736
27647
10450
60680
16243
76467
63114
56999
93751
70610
43297
65252
96484
53292
89010
31184
39959
62559
49272
9533
80919
6876
83742
58553
74286
50737
34694
90400
21366
40641
41...

output:

957623588
419032934
237992356
923701323
169124718
406856879
593232837
599881909
520793745
437877846
459606271
328788319
490258904
5531643
433844669
477483744
593243118
651540063
853407719
511541684
856211513
127790699
783554402
35283007
217337906
986073774
447233357
625823082
650479956
156125060
662...

result:

ok 100000 lines

Test #12:

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

input:

100000
93620
97547
99805
98366
90172
91659
93266
91936
98841
99388
92577
96281
95406
93126
93992
91794
92945
93167
94645
96611
93371
99002
98277
91240
94911
97886
92211
99992
95631
92571
90014
94321
98198
93857
97577
93501
94179
91790
94437
99526
95584
95273
98507
95698
99486
90991
92069
91655
95729...

output:

450853432
426002620
650006020
421489030
106862387
329032699
900706232
602846325
868949171
748526360
91132452
675572907
304908455
507361493
557032887
925867642
438112603
268890232
129209530
210219237
772617916
448424385
111636545
488121680
861240714
241815158
13253286
589892457
804265562
242801707
63...

result:

ok 100000 lines