48442023-03-31 20:29:35AblablablaInverziócpp17Accepted 50/50192ms11716 KiB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

int main()
{
    int n;
    cin >> n;
    vector<int> indexek(n + 1, 0);
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        indexek[a] = i + 1;
    }

    vector<int> dp(n + 1, 0);
    dp[1] = -1;
    bool vanVal = false;
    pii valasz = {0, 0};
    pii kovi = {1, indexek[1]};

    for(int i = 2; i <= n; i++){
        if(kovi.second > indexek[i]){
            dp[i] = kovi.second;
        } else{
            dp[i] = -1;
            kovi.second = indexek[i];
            kovi.first = i;
        }

        if(dp[i] != -1 && valasz.second - valasz.first < dp[i] - indexek[i]){
            valasz.first = indexek[i];
            valasz.second = dp[i];
            vanVal = 1;
        }
    }

    if(vanVal){
        cout << valasz.first << " " << valasz.second << "\n";
    } else{
        cout << "-1\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1812 KiB
2Accepted0/017ms2708 KiB
3Accepted1/13ms2088 KiB
4Accepted2/23ms2224 KiB
5Accepted7/73ms2488 KiB
6Accepted2/217ms3152 KiB
7Accepted2/2173ms10396 KiB
8Accepted2/2179ms10356 KiB
9Accepted2/2180ms10636 KiB
10Accepted2/2175ms10640 KiB
11Accepted2/2177ms10892 KiB
12Accepted2/2172ms10916 KiB
13Accepted2/2192ms10952 KiB
14Accepted2/2177ms10848 KiB
15Accepted2/2173ms10848 KiB
16Accepted2/2175ms11104 KiB
17Accepted2/2178ms11248 KiB
18Accepted2/2180ms11608 KiB
19Accepted3/3173ms11384 KiB
20Accepted3/3174ms11572 KiB
21Accepted2/2173ms11516 KiB
22Accepted2/2178ms11668 KiB
23Accepted2/2177ms11704 KiB
24Accepted2/2173ms11716 KiB