652021-01-09 16:26:43Kevinke12Inverziócpp11Time limit exceeded 46/50547ms13844 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

vector<int> t;
int dp[500005];
int hely[500005];
int N, kezd=-1, veg=-200000, be;

int Melyik(int szam)
{
    for(int i = szam+1; i <= N; i++)
    {
        if(dp[i]!=0)
            return i;
    }
    return szam;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    cin >> N;
    for(int i = 0; i < N; i++)
    {
        cin >> be;
        t.push_back(be);
        hely[be]=i;

        dp[t[i]]=t[i]; //onmaga
        dp[t[i]] = dp[Melyik(t[i])];

        if(abs(hely[t[i]]-hely[dp[t[i]]]) > veg-kezd)
        {
            kezd=min(hely[t[i]], hely[dp[t[i]]]);
            veg=max(hely[t[i]], hely[dp[t[i]]]);
        }
    }
    /*for(int i = 1; i <= N; i++)
    {
        if(abs(hely[i]-hely[dp[i]]) > veg-kezd)
        {
            kezd=min(hely[i], hely[dp[i]]);
            veg=max(hely[i], hely[dp[i]]);
        }
    }*/
    if((kezd==-1) || (kezd==veg))
        cout << "-1\n";
    else
        cout << kezd+1 << " " << veg+1 << "\n";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base46/50
1Accepted0/02ms1832 KiB
2Accepted0/014ms3308 KiB
3Accepted1/11ms1916 KiB
4Accepted2/21ms1936 KiB
5Accepted7/71ms1940 KiB
6Accepted2/28ms3336 KiB
7Time limit exceeded0/2500ms13740 KiB
8Accepted2/2103ms13788 KiB
9Accepted2/2100ms13824 KiB
10Accepted2/287ms13584 KiB
11Accepted2/286ms13744 KiB
12Accepted2/293ms13824 KiB
13Accepted2/292ms13748 KiB
14Accepted2/283ms13840 KiB
15Accepted2/2391ms13776 KiB
16Accepted2/294ms13804 KiB
17Accepted2/285ms13844 KiB
18Accepted2/285ms13780 KiB
19Accepted3/3377ms13772 KiB
20Accepted3/3490ms13812 KiB
21Accepted2/2497ms13772 KiB
22Accepted2/290ms13836 KiB
23Accepted2/2101ms13832 KiB
24Time limit exceeded0/2547ms1044 KiB