622021-01-09 16:25:15Kevinke12Inverziócpp11Time limit exceeded 44/50521ms70800 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
base44/50
1Accepted0/02ms1828 KiB
2Accepted0/014ms3612 KiB
3Accepted1/11ms2212 KiB
4Accepted2/21ms2236 KiB
5Accepted7/71ms2240 KiB
6Accepted2/28ms3912 KiB
7Time limit exceeded0/2503ms17612 KiB
8Accepted2/294ms20912 KiB
9Accepted2/2109ms24332 KiB
10Accepted2/283ms27440 KiB
11Accepted2/281ms30864 KiB
12Accepted2/286ms34152 KiB
13Accepted2/285ms37572 KiB
14Accepted2/283ms40812 KiB
15Accepted2/2397ms44156 KiB
16Accepted2/289ms47508 KiB
17Accepted2/2101ms50884 KiB
18Accepted2/298ms54152 KiB
19Accepted3/3398ms57428 KiB
20Accepted3/3472ms60760 KiB
21Time limit exceeded0/2504ms64036 KiB
22Accepted2/292ms67452 KiB
23Accepted2/293ms70800 KiB
24Time limit exceeded0/2521ms58028 KiB