QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#535977#4835. ModetarjenTL 2ms3808kbC++202.9kb2024-08-28 17:09:242024-08-28 17:09:25

Judging History

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

  • [2024-08-28 17:09:25]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:3808kb
  • [2024-08-28 17:09:24]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
struct Gmx{
    vector<int> val,cnt;
    int n,all,mx;
    Gmx(int _n=0,int _all=0):n(_n),all(_all){
        val.resize(all+1);
        cnt.resize(n+1);
        cnt[0]=n;
        mx=0;
    }
    void add(int x){
        cnt[val[x]]--;
        val[x]++;
        cnt[val[x]]++;
        mx=max(mx,val[x]);
    }
    void del(int x){
        cnt[val[x]]--;
        val[x]--;
        cnt[val[x]]++;
        if(cnt[mx]==0)mx--;
    }
    int getmax(){
        return mx;
    }
};
void gmax(int &x,int y){
    if(y>x)x=y;
}
const int N=400;
void solve()
{
    int n;cin>>n;
    vector<int> all;
    auto getid = [&](int x){
        return lower_bound(all.begin(),all.end(),x)-all.begin()+1;
    };
    vector<int> a(n+1);
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)all.push_back(a[i]);
    sort(all.begin(),all.end());
    all.resize(unique(all.begin(),all.end())-all.begin());
    int cnt=(int)all.size();
    vector<vector<int>> ve(cnt+1);
    for(int i=1;i<=n;i++)a[i]=getid(a[i]),ve[a[i]].push_back(i);
    vector<int> ans(cnt+1);
    for(int i=1;i<=cnt;i++)ans[i]=(int)ve[a[i]].size();
    for(int t=1;t<=N;t++){
        Gmx sol(n,cnt),sol2(n,cnt);
        for(int i=1;i<=n;i++)sol2.add(a[i]);
        int j=0;
        while(sol.mx<t&&j<n){++j;sol.add(a[j]);sol2.del(a[j]);}
        if(sol.mx!=t)break;
        for(int i=1;i<=n;i++){
            if(i>0)gmax(ans[a[i-1]],sol2.val[a[i-1]]+t);
            sol.del(a[i]);
            while(sol.mx<t&&j<n){
                j++;
                gmax(ans[a[j]],sol2.val[a[j]]+t);
                sol.add(a[j]);
                sol2.del(a[j]);
            }
            sol2.add(a[i]);
            if(sol.mx!=t)break;
        }
    }
    vector<int>sum(n+1);
    vector<int>pr(cnt+1),now(cnt+1);
    for(int z=1;z<=cnt;z++)if((int)ve[z].size()>=N){
        for(int i=1;i<=n;i++){
            sum[i]=sum[i-1]+(a[i]==z);
        }
        for(int i=1;i<=cnt;i++)pr[i]=0,now[i]=0;
        for(int i=1;i<=n;i++)if(a[i]!=z){
            now[a[i]]+=sum[i]-sum[pr[a[i]]];
            // cout<<"z="<<z<<" i="<<i<<" now="<<now[a[i]]<<" ans="<<(int)ve[a[i]].size()+now[a[i]]<<endl;
            gmax(ans[a[i]],(int)ve[a[i]].size()+now[a[i]]);
            now[a[i]]--;
            if(now[a[i]]<0)now[a[i]]=0;
            pr[a[i]]=i;
        }
        for(int i=1;i<=cnt;i++)pr[i]=n,now[i]=0;
        for(int i=1;i<=n;i++)if(a[i]!=z){
            now[a[i]]+=sum[pr[a[i]]]-sum[i];
            // cout<<"z="<<z<<" i="<<i<<" now="<<now[a[i]]<<" ans="<<(int)ve[a[i]].size()+now[a[i]]<<endl;
            gmax(ans[a[i]],(int)ve[a[i]].size()+now[a[i]]);
            now[a[i]]--;
            if(now[a[i]]<0)now[a[i]]=0;
            pr[a[i]]=i;
        }
    }
    int max_ans=*max_element(ans.begin(),ans.end());
    cout<<max_ans<<"\n";
    for(int i=1;i<=cnt;i++)if(ans[i]==max_ans)cout<<all[i-1]<<"\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;cin>>T;while(T--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
5
1 2 3 2 1
5
1 1 3 1 1
6
2 4 2 4 8 8
5
1 2 3 4 5

output:

4
1
5
1
4
2
4
8
2
1
2
3
4
5

result:

ok 14 numbers

Test #2:

score: 0
Accepted
time: 2ms
memory: 3624kb

input:

10
300
336470888 634074578 642802746 167959139 642802746 481199252 481199252 481199252 167959139 634074578 634074578 336470888 336470888 481199252 642802746 481199252 481199252 167959139 642802746 634074578 167959139 336470888 634074578 642802746 167959139 481199252 167959139 167959139 167959139 481...

output:

80
481199252
634074578
46
153774342
39
846318354
30
937534594
27
698063951
27
419330425
20
603780410
706588687
801036056
20
541308492
19
352404708
16
187061768
428773075

result:

ok 24 numbers

Test #3:

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

input:

10
300
641009859 804928248 804928248 804928248 804928248 641009859 476927808 641009859 641009859 641009859 75475634 804928248 804928248 641009859 804928248 54748096 75475634 75475634 54748096 75475634 54748096 54748096 476927808 476927808 75475634 476927808 641009859 75475634 476927808 476927808 754...

output:

84
75475634
47
173884819
253838924
593535580
37
119584259
29
66715052
671541499
706982083
25
683509776
23
145885283
637691905
26
968506132
18
277852473
891198181
954696748
18
967045702
19
493331319

result:

ok 27 numbers

Test #4:

score: 0
Accepted
time: 1ms
memory: 3640kb

input:

10
300
923264237 524125987 524125987 524125987 923264237 751244358 374288891 923264237 923264237 923264237 535590429 524125987 374288891 751244358 524125987 923264237 751244358 751244358 923264237 751244358 535590429 535590429 751244358 923264237 751244358 524125987 751244358 923264237 524125987 923...

output:

85
524125987
50
475906689
38
802613215
28
824887911
28
506836893
754648411
23
708438632
731263599
20
210467639
284624362
746100908
806519500
980100704
21
797383894
21
156438550
977566828
17
111777754

result:

ok 27 numbers

Test #5:

score: 0
Accepted
time: 1ms
memory: 3616kb

input:

10
300
702209411 496813081 561219907 702209411 702209411 561219907 730593611 496813081 702209411 561219907 673102149 702209411 496813081 702209411 673102149 496813081 730593611 496813081 673102149 702209411 673102149 673102149 496813081 496813081 702209411 673102149 561219907 702209411 561219907 561...

output:

81
496813081
53
675266630
38
767363622
32
404396525
27
118275344
195136790
21
422498140
522949042
869477976
887728896
998214353
22
611458649
20
298642883
618165181
853396846
18
510545542
18
41119063
42804963
383659701

result:

ok 29 numbers

Test #6:

score: -100
Time Limit Exceeded

input:

6
200000
564718673 564718673 291882089 291882089 412106895 291882089 291882089 412106895 564718673 564718673 412106895 412106895 412106895 564718673 291882089 564718673 412106895 291882089 564718673 291882089 564718673 291882089 291882089 564718673 291882089 412106895 564718673 291882089 564718673 5...

output:


result: