这代码过了测试,在我的VS上居然跑不了?
查看原帖
这代码过了测试,在我的VS上居然跑不了?
1380473
ZY_202301005129楼主2024/10/6 21:34
#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;
}

运行之后甚至都无法输入,调试了直接报错,什么情况?

2024/10/6 21:34
加载中...