82752024-01-14 08:28:21MagyarKendeSZLGHőségriadó (50 pont)cpp17Accepted 50/5024ms4860 KiB
#include <bits/stdc++.h>
#define speed cin.tie(0); ios::sync_with_stdio(0)
using namespace std;

int N;

vector<int> ranges(const vector<int>& tempS, int K, bool mn) {
    vector<int> v(N - K + 1);
    deque<int> q;

    for (int i = 0; i < N; i++) {
        while (!q.empty() && i - q.front() >= K) q.pop_front();
        while (!q.empty() && (
            mn ? tempS[q.back()] >= tempS[i] : 
            tempS[q.back()] <= tempS[i]
        )) q.pop_back();
        
        q.push_back(i);

        if (i >= K - 1) {
            v[i - K + 1] = tempS[q.front()];
        }
    }
    
    return v;
}

bool rsml(const vector<int>& v, int i, int j, int F) {
    for (; i <= j; i++) {
        if (v[i] >= F) return 0;
    }
    return 1;
}

bool rbg(const vector<int>& v, int i, int j, int F) {
    for (; i <= j; i++) {
        if (v[i] <= F) return 0;
    }
    return 1;
}

int main() {
    int K, L, F;
    cin >> N >> K >> L >> F;

    vector<int> tempS(N);
    for (int& x : tempS) cin >> x;

    if (N < K || N < L) {
        cout << 0;
        exit(0);
    }

    int result = 0;
    bool alert = 0;
    for (int i = K - 1; i < N; i++) {
        if (!alert && rbg(tempS, i - K + 1, i, F)) {
            alert = 1;
            result++;
        }
        else if (0 <= i - L + 1 && alert && rsml(tempS, i - L + 1, i, F)) {
            alert = 0;
        }
    }

    cout << result;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1816 KiB
2Accepted0/024ms2756 KiB
3Accepted2/23ms2216 KiB
4Accepted2/23ms2460 KiB
5Accepted2/23ms2676 KiB
6Accepted2/23ms3124 KiB
7Accepted2/23ms3200 KiB
8Accepted4/43ms3348 KiB
9Accepted4/410ms3864 KiB
10Accepted4/413ms3816 KiB
11Accepted4/416ms3948 KiB
12Accepted4/413ms3892 KiB
13Accepted4/419ms3996 KiB
14Accepted4/44ms3844 KiB
15Accepted4/423ms4860 KiB
16Accepted4/423ms4816 KiB
17Accepted4/423ms4860 KiB