BOJ 11003 최솟값 찾기

Jmnote (토론 | 기여)님의 2024년 2월 2일 (금) 18:16 판 (새 문서: ==개요== {{BOJ |단계= 47 |분류1= 자료 구조 |분류2= 우선순위 큐 |분류3= 덱 }} ==C++== <syntaxhighlight lang='cpp'> #include <bits/stdc++.h> using namespace std; i...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요

BOJ 11003 최솟값 찾기

2 C++

#include <bits/stdc++.h>
using namespace std;

int N, L;
int A[5000000];
int D[5000000];

void solve() {
    deque<int> window;
    for (int i = 0; i < N; i++) {
        while (!window.empty() && window.front() <= i - L) {
            window.pop_front();
        }
        while (!window.empty() && A[window.back()] >= A[i]) {
            window.pop_back();
        }
        window.push_back(i);
        D[i] = A[window.front()];
    }
    for (int i = 0; i < N; i++) {
        cout << D[i] << ' ';
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> L;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    };
    solve();
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}