ZY_202301005129 @ 2024-10-06 21:34:45
#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;
}
运行之后甚至都无法输入,调试了直接报错,什么情况?
by syj2017 @ 2024-10-06 21:42:45
VS(非VS CODE)支持万能头吗?
by ZY_202301005129 @ 2024-10-06 21:44:45
@syj2017 不是这个的问题,我的vs我手动加了万能头
by Little_corn @ 2024-10-06 21:46:34
试着把 int a[1000001] = { 0 }; deque<int> q; int n, k;
移到外面
by ZY_202301005129 @ 2024-10-06 21:48:28
@syj2017 搞清楚了,是这个a数组的问题,a数组没设为全局变量,所以我的IDE在运行时创建的时候直接超时了
by ZY_202301005129 @ 2024-10-06 21:50:05
@Little_corn 是这样的,已经解决了