#include <bits/stdc++.h>
using namespace std;
int main()
{
int a[1000001] = { 0 };
deque<int> q;
int n, k;
cin >> n >> k;
for (int i = 1;i <= n;i++)
{
cin >> a[i];
}
for (int i = 1;i <= n;i++)
{
while (!q.empty() && a[q.back()] > a[i])//a[i]相当于是新来的元素
q.pop_back();
q.push_back(i);
if (i >= k)
{
while (!q.empty() && q.front() <= i - k)
q.pop_front();
cout << a[q.front()] << ' ';
}
}
cout << '\n';
while (!q.empty())
q.pop_front();
for (int i = 1;i <= n;i++)
{
while (!q.empty() && a[q.back()] < a[i])//a[i]相当于是新来的元素
q.pop_back();
q.push_back(i);
if (i >= k)
{
while (!q.empty() && q.front() <= i - k)
q.pop_front();
cout << a[q.front()] << ' ';
}
}
return 0;
}
运行之后甚至都无法输入,调试了直接报错,什么情况?