57522023-09-16 12:44:40AblablablaFasor (40)cpp17Accepted 40/4093ms19988 KiB
#include <bits/stdc++.h>

using namespace std;

struct segTree{
    int meret = 1;
    vector<int> fa;

    void letrehoz(int n){
        while(meret < n){
            meret *= 2;
        }

        fa.assign(2 * meret - 1, 0);
    }

    int epit(int a, int b, int ind){
        if(a == b){
            return fa[ind];
        }

        int k = (a + b) / 2;

        return fa[ind] = max(epit(a, k, 2 * ind + 1), epit(k + 1, b, 2 * ind + 2));
    }

    int keres(int a, int b, int ind, int kezd, int veg){
        if(b < kezd || veg < a){
            return 0;
        } else if(kezd <= a && b <= veg){
            return fa[ind];
        }

        int k = (a + b) / 2;
        return max(keres(a, k, 2 * ind + 1, kezd, veg), keres(k + 1, b, 2 * ind + 2, kezd, veg));
    }
};

int main()
{
    int n, k;
    cin >> n >> k;

    segTree fa;
    fa.letrehoz(n);
    vector<int> eredeti(n, 0);

    for(int i = 0; i < n; i++){
        cin >> fa.fa[fa.meret - 1 + i];
        eredeti[i] = fa.fa[fa.meret - 1 + i];
    }

    fa.epit(0, fa.meret - 1, 0);

    for(int i = 0; i < n; i++){
        int maxi = fa.keres(0, fa.meret - 1, 0, max(0, i - k), min(i + k, n));

        if(maxi == eredeti[i]){
            cout << i + 1 << "\n";
            return 0;
        }
    }

    cout << "-1\n";
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1944 KiB
2Accepted0/06ms2376 KiB
3Accepted2/23ms2328 KiB
4Accepted2/23ms2536 KiB
5Accepted2/22ms2576 KiB
6Accepted2/23ms2812 KiB
7Accepted2/23ms2936 KiB
8Accepted2/23ms3300 KiB
9Accepted2/26ms3796 KiB
10Accepted2/26ms3840 KiB
11Accepted2/26ms3780 KiB
12Accepted2/24ms4104 KiB
13Accepted2/252ms7352 KiB
14Accepted2/246ms7960 KiB
15Accepted2/268ms11632 KiB
16Accepted2/276ms12852 KiB
17Accepted2/279ms14432 KiB
18Accepted2/286ms15904 KiB
19Accepted2/293ms17288 KiB
20Accepted2/230ms15020 KiB
21Accepted2/270ms18660 KiB
22Accepted2/279ms19988 KiB