QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#709076#9486. Random MexXY_ElevenTL 351ms4208kbC++234.3kb2024-11-04 11:14:142024-11-04 11:14:14

Judging History

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

  • [2024-11-04 11:14:14]
  • 评测
  • 测评结果:TL
  • 用时:351ms
  • 内存:4208kb
  • [2024-11-04 11:14:14]
  • 提交

answer

#include <bits/stdc++.h>
// #include <windows.h>
// #include <bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
//#pragma GCC optimize(3)
#define DB double
#define LL long long
#define ULL unsigned long long
#define in128 __int128
#define cint const int
#define cLL const LL
#define For(z,e1,e2) for(int z=(e1);z<=(e2);z++)
#define Rof(z,e1,e2) for(int z=(e2);z>=(e1);z--)
#define For_(z,e1,e2) for(int z=(e1);z<(e2);z++)
#define Rof_(z,e1,e2) for(int z=(e2);z>(e1);z--)
#define inint(e) scanf("%d",&e)
#define inll(e) scanf("%lld",&e)
#define inpr(e1,e2) scanf("%d%d",&e1,&e2)
#define in3(e1,e2,e3) scanf("%d%d%d",&e1,&e2,&e3)
#define outint(e) printf("%d\n",e)
#define outint_(e) printf("%d%c",e," \n"[i==n])
#define outint2_(e,e1,e2) printf("%d%c",e," \n"[(e1)==(e2)])
#define outll(e) printf("%lld\n",e)
#define outll_(e) printf("%lld%c",e," \n"[i==n])
#define outll2_(e,e1,e2) printf("%lld%c",e," \n"[(e1)==(e2)])
#define exc(e) if(e) continue
#define stop(e) if(e) break
#define ret(e) if(e) return
#define ll(e) (1ll*(e))
#define pb push_back
#define ft first
#define sc second
#define pii pair<int,int> 
#define pli pair<long long,int> 
#define vct vector 
#define clean(e) while(!e.empty()) e.pop()
#define all(ev) ev.begin(),ev.end()
#define sz(ev) ((int)ev.size())
#define debug(x) printf("%s=%d\n",#x,x)
#define x0 __xx00__
#define y1 __yy11__
#define ffo fflush(stdout)
cLL mod=998244353ll,G=404ll;
// cLL mod[2]={1686688681ll,1666888681ll},base[2]={166686661ll,188868881ll};
template <typename Type> void get_min(Type &w1,const Type w2) { if(w2<w1) w1=w2; } template <typename Type> void get_max(Type &w1,const Type w2) { if(w2>w1) w1=w2; }
// template <typename Type> Type up_div(Type w1,Type w2) { return (w1/w2+(w1%w2?1:0)); }
template <typename Type> Type gcd(Type X_,Type Y_) { Type R_=X_%Y_; while(R_) { X_=Y_; Y_=R_; R_=X_%Y_; } return Y_; } template <typename Type> Type lcm(Type X_,Type Y_) { return (X_/gcd(X_,Y_)*Y_); }
template <typename Type> Type md(Type w1,const Type w2=mod) { w1%=w2; if(w1<0) w1+=w2; return w1; } template <typename Type> Type md_(Type w1,const Type w2=mod) { w1%=w2; if(w1<=0) w1+=w2; return w1; }
void ex_gcd(LL &X_,LL &Y_,LL A_,LL B_) { if(!B_) { X_=1ll; Y_=0ll; return ; } ex_gcd(Y_,X_,B_,A_%B_); X_=md(X_,B_); Y_=(1ll-X_*A_)/B_; } LL inv(LL A_,LL B_=mod) { LL X_=0ll,Y_=0ll; ex_gcd(X_,Y_,A_,B_); return X_; }
template <typename Type> void add(Type &w1,const Type w2,const Type M_=mod) { w1=md(w1+w2,M_); } void mul(LL &w1,cLL w2,cLL M_=mod) { w1=md(w1*md(w2,M_),M_); } template <typename Type> Type pw(Type X_,Type Y_,Type M_=mod) { Type S_=1; while(Y_) { if(Y_&1) mul(S_,X_,M_); Y_>>=1; mul(X_,X_,M_); } return S_; }
template <typename Type> Type bk(vector <Type> &V_) { auto T_=V_.back(); V_.pop_back(); return T_; } template <typename Type> Type tp(stack <Type> &V_) { auto T_=V_.top(); V_.pop(); return T_; } template <typename Type> Type frt(queue <Type> &V_) { auto T_=V_.front(); V_.pop(); return T_; }
template <typename Type> Type bg(set <Type> &V_) { auto T_=*V_.begin(); V_.erase(V_.begin()); return T_; } template <typename Type> Type bk(set <Type> &V_) { auto T_=*prev(V_.end()); V_.erase(*prev(V_.end())); return T_; }
mt19937 gen(time(NULL)); int rd() { return abs((int)gen()); }
int rnd(int l,int r) { return rd()%(r-l+1)+l; }
void main_init()
{

}
cint N=8010,M=8010;
int n,m;
LL d1[M],d2[M],z[M];
LL C(int n_,int m_)
{
    return (d1[n_]*(d2[m_]*d2[n_-m_]%mod)%mod);
}
void main_solve()
{
    inpr(n,m);
    For(i,0,m) z[i]=pw(1ll*i,1ll*n);
    d1[0]=1ll; For(i,1,m+1) d1[i]=d1[i-1]*i%mod;
    d2[m+1]=inv(d1[m+1]); Rof(i,1,m+1) d2[i-1]=d2[i]*i%mod;
    LL ans=0ll;
    /*For(i,1,m) For(j,0,i)
    {
        // printf("%d,%d:%lld\n",i,j,C(i,j)*((j&1)?1ll:-1ll)*z[m-j]);
        add(ans,C(i,j)*((j&1)?-1ll:1ll)*z[m-j]);
    }*/
    For(i,0,m)
    {
        LL s=C(m+1,i+1);
        // For(j,i,m) add(s,C(j,i));
        add(ans,s*z[m-i]*((i&1)?-1ll:1ll));
    }
    add(ans,-z[m]);
    mul(ans,inv(z[m]));
    outll(ans);
}
int main()
{
    // ios::sync_with_stdio(0); cin.tie(0);
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    // srand(time(NULL));
    main_init();
    int _; inint(_); For(__,1,_) // T>1 ?
        // printf("\n------------\n\n"),
        main_solve();
    return 0;
}
/*

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4076kb

input:

4
3 2
1 1
20 23
8000 8000

output:

374341634
1
111675632
994279778

result:

ok 4 tokens

Test #2:

score: 0
Accepted
time: 0ms
memory: 3968kb

input:

5
60 26
33 95
18 89
82 12
77 36

output:

945602338
254913692
403396795
820508695
360125985

result:

ok 5 tokens

Test #3:

score: 0
Accepted
time: 0ms
memory: 3964kb

input:

5
23 13
95 8
73 19
72 74
23 51

output:

788774542
935467825
483603650
274447212
738760583

result:

ok 5 tokens

Test #4:

score: 0
Accepted
time: 0ms
memory: 3924kb

input:

5
7 79
47 12
64 29
23 59
88 21

output:

238359778
424364643
993714623
760177301
865871793

result:

ok 5 tokens

Test #5:

score: 0
Accepted
time: 0ms
memory: 3928kb

input:

5
39 47
22 33
2 58
43 45
32 67

output:

68068469
21035974
735626561
965644028
137192045

result:

ok 5 tokens

Test #6:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

5
57 73
20 64
18 72
56 64
9 58

output:

218207240
814770590
121270366
636721674
420274847

result:

ok 5 tokens

Test #7:

score: 0
Accepted
time: 0ms
memory: 3980kb

input:

5
100 100
100 99
99 100
98 99
99 97

output:

585389012
131732771
619127511
549657738
490584077

result:

ok 5 tokens

Test #8:

score: 0
Accepted
time: 351ms
memory: 4144kb

input:

1922
4663 5021
7459 306
3249 6943
4902 4260
6118 5364
4997 7021
6772 3346
3916 7327
7156 4792
1228 5381
3240 7026
131 5713
1120 5334
2186 610
7638 2846
891 6274
5363 426
1335 7417
2127 396
323 7781
5435 1922
4989 5238
2886 3788
5413 1384
7624 4245
7191 6758
7755 5835
7660 1787
1043 7586
803 7889
79 ...

output:

672342508
406758717
456109836
583347519
254351863
547587964
177045319
935533988
555369350
136991350
790497273
429246740
670208582
782070778
169184793
771435402
251034885
528072506
303570823
257245963
629853925
267752975
350150586
786769060
44222606
607226242
320315817
861879910
752261031
341472947
2...

result:

ok 1922 tokens

Test #9:

score: 0
Accepted
time: 291ms
memory: 4196kb

input:

1569
1690 3118
4489 1453
6866 3161
6664 1290
2600 7962
6689 4642
522 772
2162 4794
3190 5987
3327 4938
6130 3823
6941 5425
3091 6213
3025 388
5330 3690
3161 6492
1740 5873
5530 1458
2496 6781
6287 5635
662 3877
3505 5138
2511 2028
3500 859
7572 813
2520 3943
7377 4768
6158 1882
7427 1702
4296 5159
5...

output:

786392950
680031668
677629004
801851613
786349751
79816839
959519914
318092993
339917671
724667845
890615671
100962701
589915015
941504560
820459949
486565344
823734064
220460851
576680186
554430485
361102164
218914963
840663949
777667686
736007308
919520675
863371619
66677855
637862969
67422276
384...

result:

ok 1569 tokens

Test #10:

score: 0
Accepted
time: 216ms
memory: 4160kb

input:

1181
4017 5052
5241 7494
7719 3875
7903 143
7280 2239
6098 2785
4900 5047
3542 4892
3011 430
4358 3184
1473 1501
2732 5656
6806 7106
6079 4418
4893 233
1746 3558
3801 650
4506 970
7836 5225
1970 1822
3342 7672
3519 1017
6258 3172
6871 3994
4143 3721
1752 2936
5806 2553
1727 3701
6464 2302
2048 3091
...

output:

648881231
526073149
469264135
392921762
374237236
765018788
699026377
457948355
693169225
754094043
700515631
122741833
428610910
661965148
268857241
313001621
686530925
177273994
339148514
571456944
973936686
176745436
23414882
360870357
623038194
895354617
386646311
288047747
236022755
955017813
1...

result:

ok 1181 tokens

Test #11:

score: 0
Accepted
time: 203ms
memory: 4140kb

input:

1080
7499 4465
5556 2341
808 1986
3404 6901
4609 4168
235 5744
5131 7261
6616 1993
4624 3943
5843 6392
4889 2743
386 6670
1188 23
4216 4225
1193 1295
6097 4160
710 2728
7146 4193
5425 4148
6206 7462
7147 1808
2381 1254
4193 1297
1359 233
991 6979
5009 6963
1824 2135
1078 6208
2893 5858
320 4173
4937...

output:

584491148
616649457
512306930
528213999
550156793
344729669
779502829
828764040
365090398
371482124
273983459
617971432
137019685
400487464
761520033
143391408
908639433
294086517
926654429
723576006
993426946
572674399
178336952
402120004
148856064
897242602
390050708
850225145
605879501
962941650
...

result:

ok 1080 tokens

Test #12:

score: 0
Accepted
time: 283ms
memory: 4208kb

input:

1534
2137 7885
2676 2513
53 3021
1623 5195
660 4999
2881 7697
6034 6429
4724 4014
5986 266
7826 726
4086 6628
7498 6114
4801 4415
5037 4206
700 6054
3497 476
1715 5892
6009 6340
1251 2345
2819 4107
7544 864
3138 4179
3909 912
180 4496
4727 2930
1057 7077
4123 2560
4963 4100
7118 463
2945 935
6573 41...

output:

676937061
816416208
899106800
778722088
621854770
637694747
789726622
647248717
143759992
290955099
204045987
17260543
508242895
836696138
605720517
462338702
426815143
443255417
341689094
660082176
461660684
531200268
467927798
816405934
307396775
786033585
765478425
774747686
67909522
155061063
47...

result:

ok 1534 tokens

Test #13:

score: -100
Time Limit Exceeded

input:

300000
1983 855
7767 4477
6925 7526
7306 5358
3987 46
5716 3789
4487 4391
4358 7525
933 1015
953 546
5716 5487
968 6561
2932 6558
6796 1429
4864 4211
5955 4414
6657 5171
2784 3725
1139 7304
553 3163
7248 6772
1977 6216
4701 7267
6130 4055
5688 1364
1335 4326
2633 3945
7851 5521
6474 2532
6869 5201
2...

output:

917986185
514093688
240004856
10138263
106086887
486293160
462563200
380236329
178495199
768072852
293049871
679765965
19413063
914310451
303877752
97576016
551398628
294935753
497649688
625770227
916721949
945723005
793837895
598750153
811171822
281042931
224310375
229099648
232754408
173968951
334...

result: