day2
作者:
__492
,
2024-05-29 19:23:44
,
所有人可见
,
阅读 2
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6+9;
int n,m,l=1,r=0;
int a[N],q[N];
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++)cin >> a[i];
deque<int>q;
for (int i = 1; i <= m; i++)
{
while (q.size() && q.back() < a[i])
q.pop_back();
q.push_back(a[i]);
}
for (int i = m; i <= n; i++)
{
while (q.size() && q.back() < a[i])
q.pop_back();
q.push_back(a[i]);
if (i - m >= 1 && q.front() == a[i - m ])
q.pop_front();
cout << q.front() << endl;
}
return 0;
}