176842025-09-13 10:13:13TakacsAndrasSíkság (55)cpp17Time limit exceeded 34/55300ms2376 KiB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
vector<int> st1,st2;
int n;
int qr1(int l, int r) {
    l += n;
    r += n;
    int rt = st1[l];
    while (l && r && l <= r) {
        if (l % 2 == 1) rt = min(rt,st1[l++]);
        if (r % 2 == 0) rt = min(rt,st1[r--]);
        l /= 2;
        r /= 2;
    }
    return rt;
}
int qr2(int l, int r) {
    l += n;
    r += n;
    int rt = st2[l];
    while (l && r && l <= r) {
        if (l % 2 == 1) rt = max(rt,st2[l++]);
        if (r % 2 == 0) rt = max(rt,st2[r--]);
        l /= 2;
        r /= 2;
    }
    return rt;
}
int main() {
    cin.tie(nullptr);
    cin >> n;
    vector<int> a(n);
    st1.resize(2*n);
    st2.resize(2*n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        st1[i+n] = a[i];
        st2[i+n] = a[i];
    }
    for (int i = n-1; i >= 0; i--) st1[i] = min(st1[i*2],st1[i*2+1]);
    for (int i = n-1; i >= 0; i--) st2[i] = max(st2[i*2],st2[i*2+1]);
    int l = 1, h = n+1;
    int out = 1;
    while (l+1 < h) {
        int m = (l+h)/2;
        int o = -1;
        for (int i = 0; i <= n-m; i++) {
            int q1 = qr1(i,i+m-1);
            int q2 = qr2(i,i+m-1);
            if (q2-q1 <= 1) {
                o = i;
                break;
            }
        }
        if (o == -1) h = m;
        else {
            l = m;
            out = o+1;
        }
    }
    cout << l << ' ' << out << '\n';
}
SubtaskSumTestVerdictTimeMemory
base34/55
1Accepted0/01ms316 KiB
2Accepted0/017ms564 KiB
3Accepted2/21ms508 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted3/31ms508 KiB
8Accepted2/22ms508 KiB
9Accepted3/32ms316 KiB
10Accepted3/317ms592 KiB
11Accepted3/313ms592 KiB
12Accepted3/33ms600 KiB
13Time limit exceeded0/3203ms2372 KiB
14Time limit exceeded0/3252ms2376 KiB
15Time limit exceeded0/3221ms2372 KiB
16Time limit exceeded0/3300ms2356 KiB
17Accepted3/3165ms2356 KiB
18Time limit exceeded0/3256ms2356 KiB
19Time limit exceeded0/3217ms2104 KiB
20Time limit exceeded0/3280ms2100 KiB
21Accepted3/372ms1332 KiB
22Accepted3/3195ms2036 KiB