662021-01-09 16:26:48Kevinke12Inverziócpp11Time limit exceeded 46/50588ms13948 KiB
#include <iostream>
#include <vector>
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/01ms1828 KiB
2Accepted0/014ms3216 KiB
3Accepted1/11ms1912 KiB
4Accepted2/21ms1932 KiB
5Accepted7/71ms1936 KiB
6Accepted2/28ms3272 KiB
7Accepted2/2495ms13808 KiB
8Accepted2/282ms13808 KiB
9Accepted2/2123ms13788 KiB
10Accepted2/2116ms13620 KiB
11Accepted2/2108ms13764 KiB
12Accepted2/281ms13948 KiB
13Accepted2/285ms13704 KiB
14Accepted2/282ms13732 KiB
15Accepted2/2395ms13720 KiB
16Accepted2/290ms13756 KiB
17Accepted2/281ms13864 KiB
18Accepted2/279ms13844 KiB
19Accepted3/3382ms13680 KiB
20Accepted3/3451ms13812 KiB
21Time limit exceeded0/2513ms13820 KiB
22Accepted2/286ms13740 KiB
23Accepted2/290ms13840 KiB
24Time limit exceeded0/2588ms1044 KiB