QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#88383#5826. 错排_UMqwq_0 0ms0kbC++202.0kb2023-03-16 09:21:192023-03-28 12:25:31

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-28 12:25:31]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-03-16 09:21:19]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define i128 __int128
#define MAXN 270010
#define p 998244353
using namespace std;
const int N=200000;
const int S=2000;
int qpow(int x,int y){
	int ret=1;
	for(;y;y>>=1,x=x*x%p)if(y&1)ret=ret*x%p;
	return ret;
}
int add(int x,int y){return x+y<p?x+y:x+y-p;}
int del(int x,int y){return x-y<0?x-y+p:x-y;}
int T,n,m;
int f[N/S+5][MAXN],g[MAXN],tmp[MAXN];
int fac[MAXN],ifac[MAXN];
int C(int x,int y){return x<y?0:fac[x]*ifac[y]%p*ifac[x-y]%p;}
namespace Poly{
	const int G=3;
	int rev[MAXN],lmt,l;
	void init(int len){
		lmt=1,l=0;while(lmt<len)lmt<<=1,l++;
		for(int i=0;i<lmt;i++)rev[i]=(rev[i>>1]>>1)|((i&1)<<(l-1));
	}
	void NTT(int *A,int sgn){
		for(int i=0;i<lmt;i++)
			if(i<rev[i])swap(A[i],A[rev[i]]);
		for(int mid=1;mid<lmt;mid<<=1){
			int Wn=qpow(G,(p-1)/(mid<<1));
			if(sgn==-1)Wn=qpow(Wn,p-2);
			for(int j=0,R=mid<<1;j<lmt;j+=R)
				for(int k=0,w=1;k<mid;k++,w=w*Wn%p){
					int x=A[j+k],y=A[j+k+mid]*w%p;
					A[j+k]=add(x,y);A[j+k+mid]=del(x,y);
				}
		}int inv=qpow(lmt,p-2);
		if(sgn==-1)
			for(int i=0;i<lmt;i++)
				A[i]=A[i]*inv%p;
	}
}
using namespace Poly;
int calc(int n,int k){
	int bel=k/S,del=k-bel*S;i128 ret=0;
	for(int i=0;i<=del&&i<=n;i++)ret+=C(del,i)*f[bel][n-i];
	return ret%p;
}
signed main(){
	freopen("qwq.in","r",stdin);
	freopen("qwq.out","w",stdout);
	init(N+S+1);//cerr<<lmt<<endl;
	fac[0]=1;for(int i=1;i<=N;i++)fac[i]=fac[i-1]*i%p;
	ifac[N]=qpow(fac[N],p-2);
	for(int i=N;i;i--)ifac[i-1]=ifac[i]*i%p;
	for(int i=0;i<=S;i++)g[i]=C(S,i);
	NTT(g,1);f[0][0]=1;
	for(int i=1;i<=N;i++)f[0][i]=(i-1)*(f[0][i-1]+(i>1?f[0][i-2]:0))%p;
	for(int i=1;i<=N/(2*S);i++){//cerr<<i<<endl;
		memcpy(tmp,f[i-1],sizeof(tmp));
		NTT(tmp,1);
		for(int j=0;j<lmt;j++)f[i][j]=tmp[j]*g[j]%p;
		NTT(f[i],-1);
		for(int j=N+1;j<lmt;j++)f[i][j]=0;
	}
	scanf("%lld",&T);
	while(T--){
		scanf("%lld%lld",&n,&m);
		if(2*m>n){puts("0");continue;}
		printf("%lld\n",C(n-m,m)*fac[m]%p*calc(n-m,m)%p);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Dangerous Syscalls

Test #1:

score: 0
Dangerous Syscalls

input:

0

output:


result:


Subtask #2:

score: 0
Dangerous Syscalls

Test #2:

score: 0
Dangerous Syscalls

input:

10
8 6
5 1
4 2
6 3
8 1
3 1
6 2
3 1
4 1
6 2

output:


result:


Subtask #3:

score: 0
Dangerous Syscalls

Test #7:

score: 0
Dangerous Syscalls

input:

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

output:


result:


Subtask #4:

score: 0
Dangerous Syscalls

Test #8:

score: 0
Dangerous Syscalls

input:

200000
4303 1473
1276 72
967 234
3619 984
1316 384
2679 50
4426 1744
3782 1179
4919 4
805 63
3933 158
1574 528
1277 435
3826 915
2739 68
2286 349
3017 527
3036 476
4280 1764
1504 686
4584 917
1379 145
4764 2178
1881 45
4808 1565
3663 165
4730 2209
2258 103
4181 1687
1636 770
4339 1173
2355 777
3201 ...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%