176762025-09-13 09:28:37TakacsAndrasFasor (40)cpp17Accepted 40/4085ms2764 KiB
#include <bits/stdc++.h>
using namespace std;
vector<int> st;
int n,k;
int qr(int l, int r) {
    l += n;
    r += n;
    int rt = st[l];
    while (l && r && l <= r) {
        if (l % 2 == 1) rt = max(rt,st[l++]);
        if (r % 2 == 0) rt = max(rt,st[r--]);
        l /= 2;
        r /= 2;
    }
    return rt;
}
int main() {
    cin >> n >> k;
    vector<int> a(n);
    st.resize(2*n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        st[i+n] = a[i];
    }
    for (int i = n-1; i >= 1; i--) st[i] = max(st[i*2],st[i*2+1]);
    for (int i = 0; i < n; i++) {
        int q = qr(max(0,i-k),min(n-1,i+k));
        if (q <= a[i]) {
            cout << i+1 << '\n';
            return 0;
        }
    }
    cout << "-1\n";
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/01ms508 KiB
2Accepted0/04ms512 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/22ms500 KiB
9Accepted2/24ms316 KiB
10Accepted2/24ms316 KiB
11Accepted2/24ms468 KiB
12Accepted2/23ms316 KiB
13Accepted2/248ms1588 KiB
14Accepted2/241ms1592 KiB
15Accepted2/267ms2764 KiB
16Accepted2/274ms2612 KiB
17Accepted2/281ms2764 KiB
18Accepted2/282ms2760 KiB
19Accepted2/285ms2612 KiB
20Accepted2/228ms1584 KiB
21Accepted2/268ms2612 KiB
22Accepted2/279ms2612 KiB