/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 284.0 KiB
#2 Accepted 17ms 668.0 KiB
#3 Accepted 16ms 648.0 KiB
#4 Accepted 17ms 680.0 KiB
#5 Accepted 17ms 664.0 KiB
#6 Accepted 19ms 1.133 MiB
#7 Accepted 19ms 936.0 KiB
#8 Accepted 16ms 568.0 KiB
#9 Accepted 6ms 564.0 KiB
#10 Accepted 6ms 588.0 KiB
#11 Accepted 15ms 1.102 MiB
#12 Accepted 15ms 1.129 MiB
#13 Accepted 15ms 1.133 MiB
#14 Accepted 20ms 1.27 MiB
#15 Accepted 17ms 984.0 KiB
#16 Accepted 17ms 1.02 MiB
#17 Accepted 17ms 1.023 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-02-29 17:09:56
Judged By
Score
100
Total Time
20ms
Peak Memory
1.27 MiB