91532024-02-15 23:05:11UVinceLegmesszebbi rossz sorrendű (35 pont)cpp17Accepted 35/3523ms13616 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    vector<pair<int, int>> m;
    int ans = -1;
    pair<int, int> ans2 = {0, 0};
    for (int i = 0; i < n; i++)
    {
        if (!m.empty())
        {
            int l = -1, r = m.size() - 1;
            while (l + 1 < r)
            {
                int cur = (l + r) / 2;
                if (m[cur].first <= v[i])
                {
                    l = cur;
                }
                else
                {
                    r = cur;
                }
            }
            if (m[r].first > v[i])
            {
                if (i - m[r].second > ans)
                {
                    ans = i - m[r].second;
                    ans2 = {m[r].second, i};
                }
            }
        }
        if (m.empty() || v[i] > m.back().first)
        {
            m.push_back({v[i], i});
        }
    }
    if (ans == -1)
    {
        cout << -1;
        return 0;
    }
    cout << ans2.first + 1 << " " << ans2.second + 1;
}
SubtaskSumTestVerdictTimeMemory
base35/35
1Accepted0/03ms1828 KiB
2Accepted0/023ms3516 KiB
3Accepted1/13ms3048 KiB
4Accepted1/13ms3104 KiB
5Accepted1/13ms3132 KiB
6Accepted1/13ms3292 KiB
7Accepted1/12ms3384 KiB
8Accepted1/13ms3656 KiB
9Accepted1/13ms3884 KiB
10Accepted1/13ms4224 KiB
11Accepted1/13ms4200 KiB
12Accepted2/28ms4960 KiB
13Accepted2/29ms5248 KiB
14Accepted2/210ms5592 KiB
15Accepted2/28ms5548 KiB
16Accepted2/210ms6384 KiB
17Accepted2/216ms6556 KiB
18Accepted2/217ms7308 KiB
19Accepted2/219ms7836 KiB
20Accepted2/220ms8684 KiB
21Accepted2/223ms9632 KiB
22Accepted2/223ms10248 KiB
23Accepted2/217ms12912 KiB
24Accepted2/217ms13616 KiB