QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#88642#5826. 错排ruizhangj0 0ms0kbC++141.6kb2023-03-16 20:38:022023-03-28 12:34:50

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:34:50]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-03-16 20:38:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;

const int N=2e5,B=450;

//const int N=10,B=20;
int inv[2*N+5],fac[2*N+5],ifac[2*N+5];
int f[B+5][N+5];
int T,a,b,n,m;
inline int calc(int x,int y,int i,int b){// x=f[i],y=f[i-1]
    return 1ll*(1ll*(i+b)*x+1ll*y)%mod*inv[i+1]%mod;
}
inline int ksm(int x,int y){
	int res=1;
	while (y){
		if (y&1) res=1ll*res*x%mod;
		x=1ll*x*x%mod;
		y>>=1;
	}
	return res;
}
//int g[N+5];
//int tcalc(int a,int b){
//	g[0]=1,g[1]=b;
//	for (int i=1;i<a;++i) g[i+1]=1ll*(1ll*g[i]*(i+b)+1ll*g[i-1])%mod*inv[i+1]%mod;
//	return g[a];
//}
int main(){
    freopen("qwq.in","r",stdin);
    freopen("qwq.out","w",stdout);
    fac[0]=fac[1]=1;
    inv[1]=1;for (int i=2;i<=2*N;++i) inv[i]=mod-1ll*(mod/i)*inv[mod%i]%mod,fac[i]=1ll*fac[i-1]*i%mod;
    ifac[2*N]=ksm(fac[2*N],mod-2);for (int i=2*N-1;i>=0;--i) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
    for (int i=0;i<=B;++i){
        int b=i*B;
        f[i][0]=1,f[i][1]=b;
        for (int j=1;j<=N;++j) f[i][j+1]=calc(f[i][j],f[i][j-1],j,b);
    }
    scanf("%d",&T);
    while (T--){
        scanf("%d%d",&n,&m);
        if (2*m>n){
            puts("0");
            continue;
        }
        a=n-2*m,b=m;
        int k=(b+B-1)/B;
        int f0=f[k][a],f1=f[k][a+1];
        if (a){
	        for (int i=k*B;i>b;--i){
	            int f2=(1ll*(a+1)*f1%mod-1ll*(a+i)*f0%mod+mod)%mod;
	            f1=(f1-f0+mod)%mod;
	            f0=(f0-f2+mod)%mod;
	        }
		}
        int ans=1ll*f0*fac[n-m]%mod*fac[m]%mod;
        printf("%d\n",ans);
    }
    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%