#include <bits/stdc++.h>
using namespace std;
int n, m;
int q[100010];
int a[100010];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> a[i];
int h = 1;
int t = 0;
//a[t] = 2e9 + 1;
for (int i = 1; i <= n; i++) {
while (h <= t && a[i] <= a[q[t]])
t--;
q[++t] = i;
while (h <= t && q[h] < i - m + 1)
h++;
if (i - m + 1 >= 1)
cout << a[q[h]] << endl;
}
}
纯纯的板子题。水水了一发。
好像有st表的做法,学会了再来补