72222024-01-03 19:19:00MagyarKendeSZLGFasor (40)cpp17Runtime error 38/4028ms6532 KiB
#include <bits/stdc++.h>

#define speed cin.tie(0); ios::sync_with_stdio(0)
#define cinv(v) for (auto& e : v) cin >> e;
#define all(v) v.begin(), v.end()
#define has(s, e) s.count(e)

using namespace std;
using ll = long long;
using point = array<int, 2>;

int main() {
    speed;

    int N, K;
    cin >> N >> K;
    vector<int> v(N);
    cinv(v);

    deque<point> q;
    
    for (int i = 0; i < K + 1; i++) {

        while (!q.empty() && q.back()[0] < v[i]) {
            q.pop_back();
        }

        q.push_back({v[i], i});
    }

    if (q.front()[0] == v[0]) {
        cout << 1;
        exit(0);
    }

    int bagoly = 1, left = 1 - K, right = 1 + K;

    while (bagoly < N) {

        if (0 <= left) {
            while (!q.empty() && q.front()[1] < left) {
                q.pop_front();
            }
        }

        if (right < N) {
            while (!q.empty() && q.back()[0] < v[right]) {
                q.pop_back();
            }

            q.push_back({v[right], right});
        }

        if (!q.empty() && q.front()[0] == v[bagoly]) {
            cout << bagoly + 1;
            exit(0);
        }

        left++;
        bagoly++;
        right++;
    }
}
SubtaskSumTestVerdictTimeMemory
base38/40
1Accepted0/03ms1860 KiB
2Accepted0/04ms2268 KiB
3Accepted2/23ms2436 KiB
4Accepted2/23ms2544 KiB
5Accepted2/23ms2744 KiB
6Accepted2/23ms2948 KiB
7Accepted2/23ms2936 KiB
8Accepted2/23ms2928 KiB
9Accepted2/24ms3048 KiB
10Accepted2/24ms3236 KiB
11Accepted2/24ms3412 KiB
12Accepted2/23ms3308 KiB
13Accepted2/216ms4564 KiB
14Runtime error0/214ms5264 KiB
15Accepted2/225ms6108 KiB
16Accepted2/226ms5800 KiB
17Accepted2/228ms6280 KiB
18Accepted2/228ms5356 KiB
19Accepted2/227ms5164 KiB
20Accepted2/213ms5044 KiB
21Accepted2/225ms6532 KiB
22Accepted2/228ms5356 KiB