19152022-12-09 23:55:20kdbSíkság (55)cpp11Accepted 55/5514ms4376 KiB
#include <iostream>
#include <vector>
#include <deque>
using namespace std;
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int>vec(n);
    for (size_t i = 0; i < n; i++) cin >> vec[i];
    deque<int>iq, aq;
    int ms = 0, me = 0, s = 0, e = 0;
    while (e<n)
    {
        int x = vec[e];
        while (!iq.empty() && vec[iq.back()] >= x) iq.pop_back();
        iq.push_back(e);
        while (!aq.empty() && vec[aq.back()] <= x) aq.pop_back();
        aq.push_back(e);

        if (vec[aq.front()] - vec[iq.front()] > 1)
        {
            s++;
            if (s > iq.front()) iq.pop_front();
            if (s > aq.front()) aq.pop_front();
        }
        else
        {
            if (me - ms < e - s)
            {
                me = e;
                ms = s;
            }
            e++;
        }
    }
    cout << me - ms + 1 << " " << ms + 1 << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms1828 KiB
2Accepted0/03ms2188 KiB
3Accepted2/22ms2336 KiB
4Accepted2/22ms2544 KiB
5Accepted2/22ms2524 KiB
6Accepted2/22ms2800 KiB
7Accepted3/32ms2940 KiB
8Accepted2/22ms3056 KiB
9Accepted3/32ms3060 KiB
10Accepted3/33ms3224 KiB
11Accepted3/33ms3280 KiB
12Accepted3/33ms3532 KiB
13Accepted3/314ms4128 KiB
14Accepted3/310ms4256 KiB
15Accepted3/313ms4108 KiB
16Accepted3/314ms4184 KiB
17Accepted3/314ms4108 KiB
18Accepted3/314ms4308 KiB
19Accepted3/314ms4376 KiB
20Accepted3/314ms4308 KiB
21Accepted3/38ms3788 KiB
22Accepted3/312ms4172 KiB