UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#205437#3688. 排列nullptr_qwq1009449ms235532kbC++112.4kb2024-07-05 11:47:082024-07-05 13:04:33

answer

// 私は猫です

#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define inf 1000000000
#define infll 1000000000000000000ll
#define pii pair<int,int>
#define rep(i,a,b,c) for(int i=(a);i<=(b);i+=(c))
#define per(i,a,b,c) for(int i=(a);i>=(b);i-=(c))
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define dF(i,a,b) for(int i=(a);i>=(b);i--)
#define cmh(sjy) while(sjy--)
#define lowbit(x) (x&(-x))
#define HH printf("\n")
#define eb emplace_back
#define poly vector<int>
using namespace std;
ll read(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return x*f;
}
const int mod=1e9+7,maxn=20000005;
inline int qpow(int x,ll y){
	int rt=1;
	for(;y;y>>=1,x=1ll*x*x%mod) if(y&1) rt=1ll*rt*x%mod;
	return rt;
}
inline void inc(int &x,int y){ x=(x+y>=mod)?(x+y-mod):(x+y); }
inline void dec(int &x,int y){ x=(x>=y)?(x-y):(x+mod-y); }
inline void mul(int &x,int y){ x=1ll*x*y%mod; }
inline int add(int x,int y){ return (x+y>=mod)?(x+y-mod):(x+y); }
inline int sub(int x,int y){ return (x>=y)?(x-y):(x+mod-y); }
inline int prod(int x,int y){ return 1ll*x*y%mod; }
inline void chkmax(int &x,int y){ x=max(x,y); }
inline void chkmin(int &x,int y){ x=min(x,y); }
// inline void chkmax(ll &x,ll y){ x=max(x,y); }
// inline void chkmin(ll &x,ll y){ x=min(x,y); }
inline int mypow(int x,int y,int Mod){
	x%=Mod; int rt=1;
	for(;y;y>>=1,x=(1ll*x*x)%Mod) if(y&1) rt=(1ll*rt*x)%Mod;
	return rt;
}
mt19937 eng(std::chrono::steady_clock::now().time_since_epoch().count());
inline int rd(int l,int r) { return std::uniform_int_distribution<int>(l,r)(eng); }
namespace combi{
	int fac[maxn],ifac[maxn],inv[maxn];
	void init(int N){
		fac[0]=ifac[0]=inv[0]=1;
		F(i,1,N) fac[i]=1ll*fac[i-1]*i%mod;
		ifac[N]=qpow(fac[N],mod-2);
		dF(i,N-1,1) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
		F(i,1,N) inv[i]=1ll*ifac[i]*fac[i-1]%mod;
	}
	inline int C(int n,int m){
		if(m>n||n<0||m<0) return 0;
		return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
	}
}
//using namespace combi;
using combi::C;
int n,A,B;
void solve(){
	n=read(),A=read(),B=read();
	if(A>B)A=n-A+1,B=n-B+1;
	int ans=1ll*sub(C(A+B-2,A-1),C(A+B-2,A-2))*sub(C(2*n-A-B,n-A),C(2*n-A-B,n-B-1))%mod;
	printf("%d\n",ans);
}
signed main(){
	combi::init(maxn-2);
	int sjy=read();
	cmh(sjy) solve();
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 5
Accepted
time: 273ms
memory: 235504kb

input:

0

output:


result:

ok 0 lines

Test #2:

score: 5
Accepted
time: 317ms
memory: 235528kb

input:

10
8 4 7
8 3 3
5 5 4
8 7 7
3 3 3
2 1 2
8 2 7
4 2 4
4 2 4
8 1 3

output:

192
84
14
132
2
1
36
3
3
297

result:

ok 10 lines

Test #3:

score: 5
Accepted
time: 311ms
memory: 235532kb

input:

10
10 6 2
15 9 11
15 1 2
15 13 1
11 1 1
13 12 12
4 4 1
14 7 12
10 6 10
15 6 6

output:

1375
1074060
2674440
104
16796
58786
1
167076
1001
204204

result:

ok 10 lines

Test #4:

score: 5
Accepted
time: 314ms
memory: 235528kb

input:

10
15 11 11
15 3 9
15 15 8
15 8 8
15 5 14
15 15 7
15 13 13
15 11 9
15 1 1
15 5 13

output:

235144
349860
62016
184041
17000
23256
416024
1074060
2674440
68040

result:

ok 10 lines

Test #5:

score: 5
Accepted
time: 328ms
memory: 235532kb

input:

10
12 2 2
50 50 24
50 7 29
50 30 9
1 1 1
50 5 16
50 42 42
50 44 14
14 13 11
50 6 33

output:

16796
784205541
136767280
743104124
1
941729692
938035517
821059486
447678
114744019

result:

ok 10 lines

Test #6:

score: 5
Accepted
time: 281ms
memory: 235532kb

input:

10
50 7 7
50 43 9
50 45 45
50 24 44
50 45 44
34 8 8
50 6 17
50 13 9
50 7 3
50 33 32

output:

609433836
726339700
149788291
539499204
756477488
412796050
93425351
44310075
764063834
554675576

result:

ok 10 lines

Test #7:

score: 5
Accepted
time: 276ms
memory: 235528kb

input:

10
17 5 13
42 33 42
47 14 46
46 4 18
50 35 41
50 29 29
50 4 1
27 27 27
50 25 34
50 46 26

output:

1587600
44981926
962984092
822619000
455089236
762803977
329601826
352943583
795062518
75183062

result:

ok 10 lines

Test #8:

score: 5
Accepted
time: 277ms
memory: 235528kb

input:

10
2000 1044 427
1055 150 568
2000 1316 1552
1850 731 777
2000 1181 115
2000 1038 211
1684 514 693
2...

output:

76158805
820159820
457004932
749947896
391982524
250531129
635640937
220612825
561164219
237015693

result:

ok 10 lines

Test #9:

score: 5
Accepted
time: 346ms
memory: 235532kb

input:

10
106 95 30
2000 1935 970
1524 1212 407
2000 91 1021
427 348 285
2000 1035 1791
1144 72 183
2000 74...

output:

578197110
894153121
646304516
761502518
749932152
805821258
328412689
825702591
439178438
953484993

result:

ok 10 lines

Test #10:

score: 5
Accepted
time: 340ms
memory: 235532kb

input:

10
2000 1729 1774
790 224 163
1886 784 784
1365 26 26
1694 604 604
546 66 404
2000 1945 840
1459 104...

output:

591013932
74308260
715811853
575719526
519809596
659317837
255276166
365596477
64739257
97176753

result:

ok 10 lines

Test #11:

score: 5
Accepted
time: 279ms
memory: 235528kb

input:

10
9314 4710 6570
100000 8346 65219
100000 23613 25811
100000 55022 70145
100000 62205 62980
100000 ...

output:

760940439
106830043
128818902
758693125
645035984
288223269
749480385
730590005
279012333
939276372

result:

ok 10 lines

Test #12:

score: 5
Accepted
time: 274ms
memory: 235528kb

input:

10
20365 19394 12528
100000 62512 11412
100000 39156 29744
100000 56561 3548
100000 75773 75773
1000...

output:

79367751
707698966
665059984
83454157
900730211
531728328
207529400
913858398
421442177
674251901

result:

ok 10 lines

Test #13:

score: 5
Accepted
time: 280ms
memory: 235528kb

input:

10
100000 41711 41711
49065 45634 37174
80270 14077 14077
3730 2257 938
64470 63506 14070
40515 3553...

output:

199845666
21919142
231518030
809928870
578533309
391385020
428571064
981259951
608926766
984520261

result:

ok 10 lines

Test #14:

score: 5
Accepted
time: 318ms
memory: 235528kb

input:

10
100000 60273 60536
45456 18322 34219
59930 10079 10079
84342 20337 58906
52675 23412 41199
100000...

output:

900982752
225128060
352975062
929180521
710814146
492356392
242285883
137878612
743773165
235221511

result:

ok 10 lines

Test #15:

score: 5
Accepted
time: 858ms
memory: 235528kb

input:

1000000
802847 469687 469687
906927 442680 373438
10000000 3216693 3216693
10000000 1866080 349088
4...

output:

517120410
211046556
137111017
691007006
577212190
296923248
540961505
885416000
368968522
380730701
...

result:

ok 1000000 lines

Test #16:

score: 5
Accepted
time: 946ms
memory: 235532kb

input:

1000000
6729 2960 3752
3232165 697562 1870699
4354757 1940033 3200647
3609501 721003 2931847
1000000...

output:

518986544
266508812
27377454
530918439
604328336
956404241
860622346
379136556
123837012
471721498
5...

result:

ok 1000000 lines

Test #17:

score: 5
Accepted
time: 889ms
memory: 235532kb

input:

1000000
10000000 2101658 2101658
10000000 7548626 2656262
5546269 5178768 5073831
9413920 8980721 19...

output:

86657242
406904505
452871734
666193042
411920208
965590749
594284677
69424405
481865696
425225834
36...

result:

ok 1000000 lines

Test #18:

score: 5
Accepted
time: 812ms
memory: 235528kb

input:

1000000
2529742 1753815 2094416
1012917 34925 37757
4732580 4458906 3312817
4593909 4117754 4117754
...

output:

800254875
73662407
904966583
613843433
959643054
733976963
273517476
769571179
375455953
217883683
3...

result:

ok 1000000 lines

Test #19:

score: 5
Accepted
time: 874ms
memory: 235532kb

input:

1000000
7897351 6566616 593687
10000000 9900362 461903
5174552 818719 818719
10000000 3832803 479194...

output:

855201630
923825105
665790323
525293617
524534813
390752400
600844126
676459047
100111901
541389582
...

result:

ok 1000000 lines

Test #20:

score: 5
Accepted
time: 856ms
memory: 235528kb

input:

1000000
5114880 3019533 2327546
10000000 5564141 98183
235488 184983 5349
7510751 2283441 2283441
10...

output:

428154248
769516564
372670453
414674154
61427139
203547474
14245529
976867367
842368812
556591870
46...

result:

ok 1000000 lines