Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <array>
- #include <vector>
- #include <numeric>
- #include <random>
- #include <chrono>
- #include <set>
- #include <map>
- #include <queue>
- #define int long long
- using namespace std;
- const long long INF = 1e9 + 7;
- const int MAXN = 15e4 + 10;
- const int N = 1e5 + 10;
- array<int, MAXN> sq, a;
- const int B = 666;
- inline void build(int n) {
- sq.fill(INF);
- for (int i = 0; i < n; ++i) {
- sq[i / B] = min(sq[i / B], a[i]);
- }
- }
- inline int get(int l, int r) {
- int ans = INF;
- while (l <= r) {
- if (l % B == 0 && l + B - 1 <= r) {
- ans = min(ans, sq[l / B]);
- l += B;
- } else {
- ans = min(ans, a[l]);
- ++l;
- }
- }
- return ans;
- }
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- int n, k;
- cin >> n >> k;
- for (int i = 0; i < n; ++i) {
- cin >> a[i];
- }
- build(n);
- int l = 0, r = k - 1;
- while (r < n) {
- cout << get(l, r) << ' ';
- ++l, ++r;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment