QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#92225#6168. 异构序列码性态问题Crysfly100 ✓494ms32236kbC++173.1kb2023-03-30 14:28:142023-03-30 18:24:43

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-30 18:24:43]
  • 评测
  • 测评结果:100
  • 用时:494ms
  • 内存:32236kb
  • [2023-03-30 14:28:14]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
//#define int long long
using namespace std;
inline int read()
{
	char c=getchar();int x=0;bool f=0;
	for(;!isdigit(c);c=getchar())f^=!(c^45);
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	if(f)x=-x;return x;
}

int mod;
struct modint{
	int x;
	modint(int o=0){x=o;}
	modint &operator = (int o){return x=o,*this;}
	modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
	modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
	modint &operator *=(modint o){return x=1ull*x*o.x%mod,*this;}
	modint &operator ^=(int b){
		modint a=*this,c=1;
		for(;b;b>>=1,a*=a)if(b&1)c*=a;
		return x=c.x,*this;
	}
	modint &operator /=(modint o){return *this *=o^=mod-2;}
	friend modint operator +(modint a,modint b){return a+=b;}
	friend modint operator -(modint a,modint b){return a-=b;}
	friend modint operator *(modint a,modint b){return a*=b;}
	friend modint operator /(modint a,modint b){return a/=b;}
	friend modint operator ^(modint a,int b){return a^=b;}
	friend bool operator ==(modint a,int b){return a.x==b;}
	friend bool operator !=(modint a,int b){return a.x!=b;}
	bool operator ! () {return !x;}
	modint operator - () {return x?mod-x:0;}
	bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
void initmod(){mod=read();}

vector<modint> fac,ifac,iv;
inline void initC(int n)
{
	if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
	int m=iv.size(); ++n;
	if(m>=n)return;
	iv.resize(n),fac.resize(n),ifac.resize(n);
	For(i,m,n-1){
		iv[i]=iv[mod%i]*(mod-mod/i);
		fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
	}
}
inline modint C(int n,int m){
	if(m<0||n<m)return 0;
	return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 5000005
#define inf 0x3f3f3f3f

int n; 
modint f[maxn];

namespace out{
    char buffer[1<<21];int p1=-1;const int p2 = (1<<21)-1;
    inline void flush(){fwrite(buffer,1,p1+1,stdout),p1=-1;}
    inline void putc(const char &x) {if(p1==p2)flush();buffer[++p1]=x;}
    template <typename T>void write(T x) {
        static char buf[15];static int len=-1;if(x>=0){do{buf[++len]=x%10+48,x/=10;}while (x);}else{putc('-');do {buf[++len]=-(x%10)+48,x/=10;}while(x);}
        while (len>=0)putc(buf[len]),--len;
    }
}

void work()
{
	initmod();
	fac.resize(0),ifac.resize(0),iv.resize(0);
	initC(n+5);
	/*
	1 998244350 998244349 998244341 998244309
	*/
	f[0]=1; f[1]=mod-3; f[2]=mod-4; 
	For(i,2,n-1)
		f[i+1]=iv[i+1]*(f[i]*(6*i-3)-f[i-1]*(i-2));
	For(i,0,n)f[i]=-f[i]; f[0]+=3,f[1]-=1;
	f[n]=f[n]*((mod+1)/2);
	out::write((fac[n]-f[n]).x),out::putc('\n');
}

signed main()
{
//	freopen("platitude.in","r",stdin);
//	freopen("platitude.out","w",stdout); 
	int T;
	while(cin>>n)work();
	out::flush();
	return 0;
}
/*
10 1000000009
*/

詳細信息

Test #1:

score: 10
Accepted
time: 4ms
memory: 24548kb

input:

1329 281979259
3946 347158051
3102 613279651
4193 175275013
494 674092373
549 240448331
3924 588857561
1719 782159639
1781 270936499
672 589936439

output:

9022243
90375289
181500274
69392605
94572085
183988942
242547795
400947287
129450662
237048756

result:

ok 10 numbers

Test #2:

score: 10
Accepted
time: 3ms
memory: 23872kb

input:

2013 239960621
2839 377547413
4864 996482101
3196 204395311
1568 653611141
753 104807119
3006 755688737
3047 697114861
2943 384316589
2413 512454407

output:

127514501
170181578
992038090
73815433
61816960
45154402
745032291
462320547
174525842
366107086

result:

ok 10 numbers

Test #3:

score: 10
Accepted
time: 4ms
memory: 23184kb

input:

4542 497374921
4375 144420547
3310 175379389
1159 776452463
642 401409289
1214 754051891
1956 962928761
3925 282058753
2664 215149997
2050 912416861

output:

234466993
4538739
59390501
366898284
163934721
171961354
863425261
138782415
83003435
201847067

result:

ok 10 numbers

Test #4:

score: 10
Accepted
time: 3ms
memory: 24580kb

input:

4808 349909687
4602 991037059
108 14516431
3384 974151743
1250 726146471
4891 585626857
3617 211451333
358 425997931
2891 654329051
4814 64701121

output:

334429486
723833033
167634
14788268
311835630
440281445
47163985
14567537
564093849
44526802

result:

ok 10 numbers

Test #5:

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

input:

1107 524640323
1847 933584471
3406 582135349
4007 51397727
80 570372863
4186 193850947
1773 505708747
59 753490921
4244 207441401
723 3432577

output:

28404629
25931058
291914063
14907567
428621355
83313071
83042152
573879485
8114266
2470622

result:

ok 10 numbers

Test #6:

score: 10
Accepted
time: 158ms
memory: 31204kb

input:

350598 149719567
5656 639718861
182032 562484129
321578 733607449
396666 977259137
289217 738297893
94787 357806747
130763 912856261
129615 332700631
439091 653900939
228198 805737671
421386 35411809

output:

17579808
155419450
560026227
468297123
243029728
56091759
321406225
561376710
276543939
567591315
340979931
27656146

result:

ok 12 numbers

Test #7:

score: 10
Accepted
time: 207ms
memory: 32236kb

input:

71980 730430429
365591 519176123
421874 939796883
442008 891121537
196686 57507407
481211 220812971
351047 410650543
262764 313392899
434798 192402149
113530 421210637
359403 379486343
396967 813975307
193616 995122811

output:

327860411
361140274
24095392
737625805
21913793
67391647
343303401
304857303
40063712
354132251
264987397
431078761
527126979

result:

ok 13 numbers

Test #8:

score: 10
Accepted
time: 267ms
memory: 31512kb

input:

412065 473565137
427460 278321429
481215 341626709
248825 235725317
391371 550178417
166694 541821383
3035 184388593
166130 370451243
342592 79808159
98863 640391243
416610 96090131
479715 456938333
407065 630349243
289928 807773149
486842 415008521
300760 618573047

output:

227856800
239201498
95049640
48786767
39159769
241480844
131425842
156263612
71199342
354783592
20708452
29520842
599940124
123311805
259947114
58026841

result:

ok 16 numbers

Test #9:

score: 10
Accepted
time: 483ms
memory: 31820kb

input:

401210 376894061
112020 976190981
76624 418721741
308217 29130763
275157 939661747
35829 250363831
178538 424627327
456973 351281803
88075 992733541
281595 311233067
104622 151994753
271593 41245261
319132 947462657
186811 961154149
227249 86441119
165977 701025443
471204 999330173
296567 685415303
...

output:

137731023
920811362
295340379
23946348
428778019
85748992
320995144
324249235
760781155
145998919
25642127
17286799
430204104
934136712
69246960
648492889
599264840
133362338
70276834
584459206
12202017
429688693
567850480
350485324
7803467
311883495
28708382
493452085
122150415
9248073
114411382
51...

result:

ok 36 numbers

Test #10:

score: 10
Accepted
time: 494ms
memory: 31744kb

input:

372965 157601299
239698 272457617
40399 596646311
315339 562161443
166279 292784099
224605 629707601
14534 7015139
478528 718703087
129027 957763397
44039 880925107
420271 933815867
323410 164444393
160117 572839451
344095 28487981
473223 648555881
469070 150428897
447149 993828707
214989 982422577
...

output:

109121987
262715175
356621013
297089637
223288225
339047279
4617668
5264280
662373976
718326466
441473337
164343771
160326216
21951599
445550765
87469418
190780668
684891016
3664088
52624980
563295409
93465252
79017843
109845265
164802142
19403970
618043168
10298288
4851762
124114770
340048759
36515...

result:

ok 40 numbers