1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| #include <bits/stdc++.h> using namespace std; const int maxn = 2e6 + 50; int n, k, head, tail, a[maxn], q[maxn];
int main() { cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) { while (head < tail && i - q[head] >= k) ++head; while (head < tail && a[q[tail - 1]] <= a[i]) --tail; q[tail++] = i; if (i >= k) cout << a[q[head]] << endl; } return 0; }
|