#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_3_D" #include <iostream> #include <vector> #include "Mylib/Algorithm/sliding_minimum.cpp" #include "Mylib/IO/input_vector.cpp" #include "Mylib/IO/join.cpp" namespace hl = haar_lib; int main() { int N, L; std::cin >> N >> L; auto a = hl::input_vector<int>(N); auto ans = hl::sliding_minimum(a, L); std::cout << hl::join(ans.begin(), ans.end()) << std::endl; return 0; }
#line 1 "test/aoj/DSL_3_D/main.test.cpp" #define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_3_D" #include <iostream> #include <vector> #line 2 "Mylib/Algorithm/sliding_minimum.cpp" #include <deque> #line 4 "Mylib/Algorithm/sliding_minimum.cpp" namespace haar_lib { template <typename T> std::vector<T> sliding_minimum(const std::vector<T> &a, int k) { const int n = a.size(); std::deque<int> dq; std::vector<T> ret; for (int i = 0; i < k; ++i) { while (not dq.empty() and a[dq.back()] >= a[i]) { dq.pop_back(); } dq.push_back(i); } for (int i = 0; i < n - k + 1; ++i) { while (dq.front() < i) { dq.pop_front(); } ret.push_back(a[dq.front()]); while (not dq.empty() and i + k < n and a[dq.back()] >= a[i + k]) { dq.pop_back(); } dq.push_back(i + k); } return ret; } } // namespace haar_lib #line 4 "Mylib/IO/input_vector.cpp" namespace haar_lib { template <typename T> std::vector<T> input_vector(int N) { std::vector<T> ret(N); for (int i = 0; i < N; ++i) std::cin >> ret[i]; return ret; } template <typename T> std::vector<std::vector<T>> input_vector(int N, int M) { std::vector<std::vector<T>> ret(N); for (int i = 0; i < N; ++i) ret[i] = input_vector<T>(M); return ret; } } // namespace haar_lib #line 3 "Mylib/IO/join.cpp" #include <sstream> #include <string> namespace haar_lib { template <typename Iter> std::string join(Iter first, Iter last, std::string delim = " ") { std::stringstream s; for (auto it = first; it != last; ++it) { if (it != first) s << delim; s << *it; } return s.str(); } } // namespace haar_lib #line 8 "test/aoj/DSL_3_D/main.test.cpp" namespace hl = haar_lib; int main() { int N, L; std::cin >> N >> L; auto a = hl::input_vector<int>(N); auto ans = hl::sliding_minimum(a, L); std::cout << hl::join(ans.begin(), ans.end()) << std::endl; return 0; }