UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214799#2161. 小L的栈erican100544ms32412kbC++112.0kb2024-11-21 21:22:532024-11-22 09:36:07

answer

/*  Erica N  */
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define int long long
#define ull unsigned long long
#define pii pair<int, int>
#define ps second
#define pf first
#define itn int
#define rd read()
int read(){
    int xx = 0, ff = 1;char ch = getchar();
    while (ch < '0' || ch > '9') {if (ch == '-')ff = -1; ch = getchar();}
    while (ch >= '0' && ch <= '9')xx = xx * 10 + (ch - '0'), ch = getchar();
    return xx * ff;
}
// void write(int out) {
// 	if (out < 0)
// 		putchar('-'), out = -out;
// 	if (out > 9)
// 		write(out / 10);
// 	putchar(out % 10 + '0');
// }
#define cdbg(x...) do { cerr << #x << " -> "; err(x); } while (0)
void err() { cerr << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cerr << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }


const int N = 2e6 + 5;
const int INF = 1e18;
const int M = 1e7;
const int MOD = 1e9 + 7;



inline int ksm(int a,int b){
    int res=1;
    while(b){
        if(b&1)res=res*a%MOD;
        b>>=1;
        a=a*a%MOD;
    }
    return res;
}


int fac[N],inv[N];

void init(){
    fac[0]=1;
    for(int i=1;i<N;i++){
        fac[i]=fac[i-1]*i%MOD;
    }
    inv[N-1]=ksm(fac[N-1],MOD-2);
    for(int i=N-1;i;i--){
        inv[i-1]=inv[i]*i%MOD;
    }

}


inline int C(int n,int m){
    if(m>n)return 0;
    return fac[n]*inv[n-m]%MOD*inv[m]%MOD;
}

// inline int Catalan(int n){
//     return fac[2*n]*inv[n+1]%MOD*inv[n]%MOD;
// }

int solve(int a,int b){
    if(a<0||b<0)return 0;
    int res=((C(a+b,b)-C(a+b,b-1))%MOD+MOD)%MOD;
    return res;
}

void solve(){  
    int n=rd,m=rd,K=rd;
    cout<<solve(n-m+K,n-m)*solve(m-1,m-K)%MOD<<endl;
}

signed main() {
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);

    init();

    cdbg("OK");
    int T=rd;
    while(T--){
        solve();
    }


}

详细

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

Test #1:

score: 5
Accepted
time: 23ms
memory: 32412kb

input:

100
26 20 10
26 24 9
13 2 2
21 13 4
29 7 5
22 19 13
12 1 1
26 1 1
24 20 2
17 15 15
3 1 1
24 14 17
25...

output:

514423014
112607261
534888
381817972
555144047
73489416
208012
352943583
53685987
152
5
0
946367425
...

result:

ok 100 lines

Test #2:

score: 5
Accepted
time: 29ms
memory: 32412kb

input:

100
13 6 3
12 6 3
14 14 13
24 15 9
8 6 5
4 3 1
4 3 2
18 12 7
23 11 5
24 20 14
14 7 3
27 21 17
31 17 ...

output:

198016
56056
13
366737601
135
4
6
39504192
967067366
715926750
636480
64591509
0
671918485
796107692...

result:

ok 100 lines

Test #3:

score: 5
Accepted
time: 20ms
memory: 32408kb

input:

100
31 18 12
11 3 1
27 9 9
7 6 2
21 15 6
16 2 1
18 11 12
22 17 5
15 6 1
10 8 10
23 22 6
28 5 6
23 4 ...

output:

661234655
9724
815886766
126
267452475
9694845
0
656127752
705432
0
581024202
0
78189099
2674440
1
4...

result:

ok 100 lines

Test #4:

score: 5
Accepted
time: 24ms
memory: 32408kb

input:

100
25 22 14
7 5 6
6 1 1
7 1 1
7 4 2
8 5 1
8 2 1
18 4 5
5 4 3
18 9 7
11 10 6
4 2 1
15 4 2
3 1 1
3 1 ...

output:

594796736
0
132
429
140
196
429
0
12
33649000
3003
5
2674440
5
5
858
24310
823378651
935508470
0
856...

result:

ok 100 lines

Test #5:

score: 5
Accepted
time: 12ms
memory: 32408kb

input:

100
29 20 6
4 4 2
6 5 3
13 9 8
5 4 4
10 5 5
30 9 11
12 12 5
8 8 4
29 5 1
16 7 2
28 8 6
3 1 1
11 11 1...

output:

763947475
5
36
10080
5
1638
0
13260
165
249143859
5542680
630775223
5
1
56
534529540
293930
27971953...

result:

ok 100 lines

Test #6:

score: 5
Accepted
time: 27ms
memory: 32412kb

input:

100
5 5 5
26 22 4
19 17 16
25 17 8
31 2 2
28 21 12
15 3 1
31 8 2
22 1 1
15 3 2
3 2 2
25 17 3
15 3 3
...

output:

1
957177681
2720
337431182
462027062
923233078
1485800
116294070
482563003
3863080
3
549208528
43459...

result:

ok 100 lines

Test #7:

score: 5
Accepted
time: 13ms
memory: 32408kb

input:

10
474 293 237
481 396 187
364 43 45
741 78 8
158 53 30
463 445 433
120 110 62
503 52 16
360 318 32
...

output:

323352985
63241071
0
222507962
478641805
854383331
893261429
747110781
699961226
252997894

result:

ok 10 lines

Test #8:

score: 5
Accepted
time: 20ms
memory: 32412kb

input:

10
641 326 203
15 3 2
153 20 25
288 240 91
499 105 31
732 581 299
994 253 153
352 106 28
62 13 10
93...

output:

919680035
3863080
0
724023677
581680580
794343262
840693979
288065703
184728173
158286453

result:

ok 10 lines

Test #9:

score: 5
Accepted
time: 13ms
memory: 32412kb

input:

10
543 141 147
663 293 26
45 31 12
69 18 22
348 49 36
37 5 4
767 411 318
421 193 84
965 44 46
398 30...

output:

0
536162423
542866247
0
356102686
284316141
577945523
655525950
0
0

result:

ok 10 lines

Test #10:

score: 5
Accepted
time: 31ms
memory: 32412kb

input:

10
999 387 390
189 157 55
324 281 150
954 62 8
514 147 89
331 236 171
150 46 15
979 216 59
682 175 1...

output:

0
657224842
866062375
612350269
797998629
965804890
33283886
370426989
0
753780884

result:

ok 10 lines

Test #11:

score: 5
Accepted
time: 16ms
memory: 32408kb

input:

10
284 110 71
343 327 228
890 627 348
756 63 8
919 31 5
542 69 21
109 15 6
424 252 155
899 5 1
192 1...

output:

939661935
7427866
845407531
565632090
584793981
721121700
999456680
490287152
790372676
0

result:

ok 10 lines

Test #12:

score: 5
Accepted
time: 20ms
memory: 32408kb

input:

10
957 341 186
433 199 51
760 510 73
406 179 137
739 207 230
74 43 43
881 518 106
118 100 29
724 475...

output:

475101795
640352890
452627676
917987052
0
220718056
847304648
569168532
840548600
367170930

result:

ok 10 lines

Test #13:

score: 5
Accepted
time: 32ms
memory: 32408kb

input:

10000
948520 153123 37633
978977 610707 430315
861510 89319 84311
89854 76753 23361
539648 26973 539...

output:

224882239
78243119
752768981
133670970
823837837
861202414
172458352
917749445
141351091
428891672
1...

result:

ok 10000 lines

Test #14:

score: 5
Accepted
time: 45ms
memory: 32412kb

input:

10000
776217 468283 394226
679502 396921 440333
336294 175951 21262
158362 85737 87647
786586 679022...

output:

593235084
0
693263768
0
239343520
75293794
855075166
448580350
971747286
415188727
0
453115359
16674...

result:

ok 10000 lines

Test #15:

score: 5
Accepted
time: 32ms
memory: 32412kb

input:

10000
727020 72982 84798
511326 476765 238661
768301 198556 241391
42904 770 3
225143 21785 19973
71...

output:

0
264209582
0
365827860
338776996
0
643364371
0
923750084
514419494
803184187
996127244
18795969
819...

result:

ok 10000 lines

Test #16:

score: 5
Accepted
time: 31ms
memory: 32408kb

input:

10000
349236 250424 6551
245300 155779 53345
718003 538775 455477
554195 3258 1970
864269 350613 163...

output:

614690665
48068909
961727825
116922077
937665053
545463810
159985171
40051945
163855553
525905370
75...

result:

ok 10000 lines

Test #17:

score: 5
Accepted
time: 39ms
memory: 32408kb

input:

10000
130797 50408 54584
589075 456571 10806
78159 33427 38224
303639 7008 8635
585821 448649 100079...

output:

0
862178676
0
0
647286860
488363651
887107171
45701820
505945040
171439785
533367105
321658620
28991...

result:

ok 10000 lines

Test #18:

score: 5
Accepted
time: 31ms
memory: 32408kb

input:

10000
693060 190134 160913
997339 460961 184242
899251 525330 137457
513519 345024 295373
352825 155...

output:

285831846
259325823
603184339
400765664
326888470
292981576
579043448
572924932
83311047
662899396
1...

result:

ok 10000 lines

Test #19:

score: 5
Accepted
time: 41ms
memory: 32412kb

input:

10000
933167 891532 704848
80961 67286 35337
240488 174845 21388
451269 212850 49163
948517 31409 36...

output:

31241498
734172905
515809396
744766113
0
934513159
814225104
928984552
459018579
830020604
141239706...

result:

ok 10000 lines

Test #20:

score: 5
Accepted
time: 45ms
memory: 32412kb

input:

10000
61939 9116 2096
150659 75224 41401
13674 12474 10722
152304 47286 14033
319787 185775 135285
8...

output:

494879849
236192375
710885048
18162371
183133441
806117830
287024099
378052720
899612100
538326070
7...

result:

ok 10000 lines