197232025-12-19 20:18:23algoproInverziócpp17Accepted 50/50194ms4336 KiB
// UUID: f6f69da9-624f-4d70-8d2f-83c9124fc000
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin>>N;
    vector<int> hisztogram(N+1, 0);
    vector<int> V(N+1);
    for(int i=1; i<=N; i++)
    {
        int a;
        cin>>a;
        V[i]=a;
        hisztogram[a-1]=i;
    }
    /*for(int i=0; i<=N; i++) cout<<hisztogram[i]<<" ";
    cout<<endl;*/
    hisztogram[N]=INT_MAX;
    for(int i=N-2; i>=1; i--)
    {
        hisztogram[i]=min(hisztogram[i], hisztogram[i+1]);
    }
    int maxi=-1;
    int maxis;
    for(int i=1; i<=N; i++)
    {
        if(i-hisztogram[V[i]]>maxi)
        {
             maxi=i-hisztogram[V[i]];
             maxis=i;
        }
    }
    /*for(int i=0; i<=N; i++) cout<<hisztogram[i]<<" ";
    cout<<endl;*/
    if(maxi==-1) cout<<-1;
    else cout<<maxis-maxi<<" "<<maxis;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms500 KiB
2Accepted0/017ms564 KiB
3Accepted1/11ms316 KiB
4Accepted2/21ms316 KiB
5Accepted7/71ms500 KiB
6Accepted2/217ms564 KiB
7Accepted2/2178ms4332 KiB
8Accepted2/2192ms4336 KiB
9Accepted2/2194ms4336 KiB
10Accepted2/2181ms4324 KiB
11Accepted2/2187ms4148 KiB
12Accepted2/2180ms4148 KiB
13Accepted2/2181ms4148 KiB
14Accepted2/2182ms4148 KiB
15Accepted2/2179ms4152 KiB
16Accepted2/2182ms4152 KiB
17Accepted2/2181ms4328 KiB
18Accepted2/2185ms4236 KiB
19Accepted3/3179ms4148 KiB
20Accepted3/3192ms4336 KiB
21Accepted2/2178ms4148 KiB
22Accepted2/2184ms4324 KiB
23Accepted2/2188ms4148 KiB
24Accepted2/2177ms4324 KiB