QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#589909#6966. 排序问题_TLEer_100 ✓574ms178680kbC++142.0kb2024-09-25 20:34:102024-09-25 20:34:12

Judging History

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

  • [2024-09-25 20:34:12]
  • 评测
  • 测评结果:100
  • 用时:574ms
  • 内存:178680kb
  • [2024-09-25 20:34:10]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
#define MOD 998244353
int jc[10200010],T,n,m,l,r,A,x[200010],p,q;
int adeld,deld,H,adm,h0,ny,invj[10200010],mxs[200010],cnt;
int ksm(int p,int q=MOD-2){
    int ans=1;
    while(q){
        if(q&1){ans=ans*p%MOD;}
        p=p*p%MOD;
        q>>=1;
    }
    return ans;
}
map<int,int> mp,mp2;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie();cout.tie();
    jc[0]=invj[0]=jc[1]=1;
    for(int i=2;i<=10200000;i++)
        jc[i]=(jc[i-1]*i)%MOD;
    invj[10200000]=ksm(jc[10200000]);
    for(int i=10199999;i>=1;i--){
        invj[i]=(invj[i+1]*(i+1))%MOD;
        assert(invj[i]*jc[i]%MOD==1);
    }
    cin>>T;
    while(T--){
        mp.clear();mp2.clear();
        cnt=0;H=-1;
        cin>>n>>m>>l>>r;
        A=jc[n+m];
        for(int i=1;i<=n;i++){
            cin>>x[i];deld=r-l+1;
            if(l<=x[i]&&x[i]<=r)
                mp2[x[i]]++;
            else mp[x[i]]++;
        }
        for(auto x:mp2)
            mxs[cnt++]=x.second;
        deld-=cnt;
        // cout<<cnt<<' '<<deld<<'\n';
        sort(mxs,mxs+cnt);
        mxs[cnt]=-1;mxs[cnt+1]=0; 
        for(h0=0;h0<cnt;){
        	adm=0;adeld=0;
            while(mxs[h0+1]==mxs[h0])
                adm+=mxs[h0],adeld++,h0++;
            adm+=mxs[h0],adeld++,h0++;
            if(adm+m>=mxs[h0-1]*(adeld+deld))H=h0,m+=adm,deld+=adeld;
        }
        for(h0=H;h0<cnt;h0++)
            if(mxs[h0])
				mp[l+h0-H]=mxs[h0];
//        if(deld>r-l+1)deld=r-l+1;
//        cout<<A<<' '<<m<<' '<<deld<<'\n';
        p=m/deld;
        q=m%deld;
        if(q&&(p+1)){
            // cout<<"A";
            // cout<<A<<'\n';
            A=(A*ksm(invj[p+1],q))%MOD;
        }
        if((deld-q)&&(p)){
            // cout<<"B";
            // cout<<A<<'\n';
            A=(A*ksm(invj[p],deld-q))%MOD;
        }
        // cout<<A<<'\n';
        for(auto x:mp)
            A=(A*invj[x.second])%MOD;
        cout<<A<<'\n';
    }
    return 0;
}

詳細信息


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 85ms
memory: 165360kb

input:

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

output:

25200
32432400
283783500
100900800
756756000
831600
6652800
15120
17160
4054050

result:

ok 10 numbers

Test #2:

score: 10
Accepted
time: 82ms
memory: 165280kb

input:

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

output:

1995840
5040
32432400
9979200
75675600
100900800
3780
3326400
33264
22680

result:

ok 10 numbers

Test #3:

score: 10
Accepted
time: 89ms
memory: 164704kb

input:

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

output:

120120
453600
83160
252252000
25200
75600
2494800
1120
1081080
226800

result:

ok 10 numbers

Test #4:

score: 10
Accepted
time: 92ms
memory: 164636kb

input:

300
252 260 70 255
7 267 105 21 192 111 287 290 88 97 39 182 76 36 8 271 138 213 16 36 70 119 8 201 278 84 152 225 226 140 265 90 31 264 206 105 82 18 160 192 10 181 66 91 142 138 174 12 66 108 135 235 160 218 93 280 187 190 115 16 205 109 103 5 35 136 36 72 158 217 240 19 161 32 191 163 170 228 30 ...

output:

817148398
610370492
73619796
392136417
552473682
653457970
930684219
606090256
975095884
234697524
896749755
40695617
733872422
843465298
644613149
962470247
616073681
286282654
600942710
443341314
464816802
236810426
248967685
639669234
379189382
286795229
934537551
908424510
72748187
143184318
462...

result:

ok 300 numbers

Test #5:

score: 10
Accepted
time: 79ms
memory: 164692kb

input:

300
227 278 55 261
255 85 153 179 43 15 8 158 281 261 243 93 242 4 129 222 202 43 279 9 219 243 63 212 38 39 152 299 224 204 267 267 34 154 250 78 40 118 98 186 12 268 277 192 84 170 248 276 96 150 232 209 56 179 82 3 240 150 11 218 173 273 81 288 187 272 140 265 272 42 208 195 86 44 73 93 279 23 19...

output:

608489105
683553113
772344021
595327909
587829438
61561996
182591455
197046497
801484762
992760752
972266746
826930864
799201428
650936985
769547619
956540936
26184676
226387568
313225809
361423520
264247840
354696853
354488314
867487992
710703238
224495630
940509905
212754645
24280788
584233214
721...

result:

ok 300 numbers

Test #6:

score: 10
Accepted
time: 135ms
memory: 173300kb

input:

1008
110000 200000 80799550 89322792
80846588 80840728 80846740 80846226 80837919 80808035 80811892 80821541 80828204 80835347 80833535 80821744 80805463 80848335 80818082 80835681 80807218 80807081 80838326 80821628 80803817 80845303 80840877 80843012 80830165 80826985 80810131 80822178 80809793 80...

output:

434108025
686210610
394302733
421678599
90720
29937600
184800
95040
113513400
554400
378378000
138600
75600
25200
454053600
181440
453600
9979200
110880
2520
50400
50400
1441440
547558588
821337882
29937600
1120
415800
454053600
129163764
7920
831600
45360
277200
138600
277200
100900800
14414400
144...

result:

ok 1008 numbers

Test #7:

score: 10
Accepted
time: 148ms
memory: 172656kb

input:

1169
100000 200000 80463410 88931820
80468507 80491681 80487314 80485519 80482007 80466540 80470566 80507366 80467570 80479753 80513204 80504461 80496204 80464814 80481678 80471573 80508511 80507514 80500322 80491106 80467094 80488511 80482243 80488511 80501739 80476062 80470590 80501419 80506225 80...

output:

868451621
486359522
502941036
201761277
3628800
75600
21527294
55440
9979200
554400
315591831
9979200
19958400
39916800
10080
504504000
119750400
9459450
100900800
277200
5040
907200
50400
362880
3603600
239500800
39916800
19958400
4989600
4989600
479001600
19958400
45360
831441387
2494800
558510847...

result:

ok 1169 numbers

Test #8:

score: 10
Accepted
time: 574ms
memory: 174016kb

input:

16681
200000 200000 76883519 76941647
76887826 76896834 76928035 76920567 76922595 76911193 76908583 76895058 76907525 76899189 76891847 76898478 76901834 76895730 76925717 76885225 76930475 76932521 76925233 76911515 76931174 76884143 76913261 76928484 76897028 76926818 76931633 76893762 76891824 7...

output:

400144591
558540649
241941311
509866966
888386043
170271298
612215140
60744581
41325256
260211701
414637790
665849438
913397652
980765230
254699744
488014740
295550767
128128274
424789214
1247400
279173343
4804800
492688569
263232904
728513423
687990592
75675600
511331093
435245378
321873426
1995840...

result:

ok 16681 numbers

Test #9:

score: 10
Accepted
time: 534ms
memory: 178680kb

input:

16652
200000 112 49071552 49072622
49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 49071552 4907...

output:

636719725
159360485
766661622
229811031
125681319
215862366
223624928
818712766
623255814
298173039
215155020
402423266
580450882
341728812
687518263
55993447
71161759
512513096
758760158
439461285
604800
252252000
977243351
620421051
378211612
8108100
236730235
179759210
5405400
664370457
12600
296...

result:

ok 16652 numbers

Test #10:

score: 10
Accepted
time: 535ms
memory: 178600kb

input:

16731
200000 104 5062478 5063630
5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 5062478 506...

output:

867024637
853235068
342602600
912521724
677376196
836451556
497157986
397366798
451218200
963540106
135969593
67177667
501624342
33196711
344393881
332568003
849320924
128128274
226800
833611556
697208287
790047185
762544679
4989600
457421435
186008666
75600
964382817
450989796
538643438
239500800
6...

result:

ok 16731 numbers

Extra Test:

score: 0
Extra Test Passed