/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 316.0 KiB
#2 Accepted 19ms 756.0 KiB
#3 Accepted 19ms 596.0 KiB
#4 Accepted 20ms 788.0 KiB
#5 Accepted 20ms 760.0 KiB
#6 Accepted 23ms 1.277 MiB
#7 Accepted 22ms 992.0 KiB
#8 Accepted 19ms 564.0 KiB
#9 Accepted 7ms 556.0 KiB
#10 Accepted 7ms 568.0 KiB
#11 Accepted 18ms 1.086 MiB
#12 Accepted 18ms 1.145 MiB
#13 Accepted 18ms 1.137 MiB
#14 Accepted 24ms 1.27 MiB
#15 Accepted 20ms 1012.0 KiB
#16 Accepted 20ms 1.016 MiB
#17 Accepted 21ms 1.012 MiB

Code

#include<bits/stdc++.h>
using namespace std;
//ofstream file("output0.txt");
void solve()
{
    int n,x; cin>>n;
    vector<int>one,two,three;
    for(int i=0;i<n;i++) 
    {
        cin>>x;
        if(x==1) one.push_back(i);
        else if(x==2) two.push_back(i);
        else if(x==3) three.push_back(i);
    }

    int ans = 0;
    int sz = one.size();
    int lo,hi,mid,ind1,ind2;
    for(auto e:one)
    {
        lo=0,hi=two.size()-1,ind1=n;
        while(lo<=hi)
        {
            mid=(lo+hi)/2;
            if(two[mid]>e)
            {
                ind1 = two[mid];
                hi=mid-1;
            }
            else lo=mid+1;
        }

        lo=0,hi=three.size()-1,ind2=-1;
        while(lo<=hi)
        {
            mid=(lo+hi)/2;
            if(three[mid]<ind1)
            {
                ind2 = three[mid];
                lo=mid+1;
            }
            else hi=mid-1;
        }

        ans = max(ans,ind2-e+1);
    }

    cout<<ans<<endl;
    //file<<ans<<endl;
}

int main()
{
    //freopen("input0.txt","r",stdin);
    int t; cin>>t; while(t--) solve();
}

Information

Submit By
Type
Submission
Problem
P1036 Perfect subarray
Language
C++20 (G++ 13.2.0)
Submit At
2024-02-29 17:09:56
Judged At
2024-11-11 03:43:09
Judged By
Score
100
Total Time
24ms
Peak Memory
1.277 MiB