82732024-01-14 08:19:04MagyarKendeSZLGHőségriadó (50 pont)cpp17Wrong answer 0/5050ms5336 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;
}

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);
    }

    vector<int> maxS = ranges(tempS, L, 0), minS = ranges(tempS, K, 1);

    for (int x : maxS) cout << x <<' '; 
    cout <<'\n';
    for (int x : minS) cout << x <<' '; 
    cout <<'\n';

    int result = 0;

    bool alert = 0;
    for (int i = 0; i < N - K + 1 && i < N - L + 1; i++) {
        if (!alert && minS[i] > F) {
            alert = 1;
            i += K - 1;
            result++;
        }
        else if (maxS[i] < F) {
            alert = 0;
            i += L - 1;
        }
    }

    cout << result;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/03ms1816 KiB
2Wrong answer0/050ms4396 KiB
3Wrong answer0/23ms2492 KiB
4Wrong answer0/23ms2764 KiB
5Wrong answer0/23ms2860 KiB
6Wrong answer0/23ms2788 KiB
7Wrong answer0/22ms2860 KiB
8Wrong answer0/43ms3020 KiB
9Wrong answer0/420ms4040 KiB
10Wrong answer0/426ms4216 KiB
11Wrong answer0/430ms4852 KiB
12Wrong answer0/426ms4408 KiB
13Wrong answer0/439ms5208 KiB
14Wrong answer0/46ms3700 KiB
15Wrong answer0/446ms5336 KiB
16Wrong answer0/446ms5336 KiB
17Wrong answer0/446ms5336 KiB