672021-01-09 16:26:54Kevinke12Inverziócpp11Time limit exceeded 44/50588ms13960 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/01ms1832 KiB
2Accepted0/014ms3280 KiB
3Accepted1/11ms1916 KiB
4Accepted2/21ms1940 KiB
5Accepted7/71ms1936 KiB
6Accepted2/28ms3360 KiB
7Time limit exceeded0/2521ms13688 KiB
8Accepted2/293ms13772 KiB
9Accepted2/2104ms13908 KiB
10Accepted2/275ms13632 KiB
11Accepted2/282ms13712 KiB
12Accepted2/281ms13960 KiB
13Accepted2/283ms13808 KiB
14Accepted2/286ms13796 KiB
15Accepted2/2418ms13772 KiB
16Accepted2/281ms13760 KiB
17Accepted2/287ms13828 KiB
18Accepted2/282ms13724 KiB
19Accepted3/3400ms13812 KiB
20Accepted3/3488ms13748 KiB
21Time limit exceeded0/2540ms13748 KiB
22Accepted2/296ms13820 KiB
23Accepted2/279ms13820 KiB
24Time limit exceeded0/2588ms1064 KiB