90分求助

P1886 滑动窗口 /【模板】单调队列

andyli @ 2018-07-27 16:22:28

第3个点WA

#include <iostream>
#include <queue>
using namespace std;
const int maxn = 1000050;

struct T
{
    int idx, v;
    T(int idx = -1, int v = -1) : idx(idx), v(v) {}
};

int A[maxn], n, k;
deque<T> q;

int main()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> A[i];
    for (int i = 0; i < n; i++)
    {
        if (i >= k)
        {
            if (q.front().idx + k < i)
                q.pop_front();
            cout << q.front().v << " ";
        }
        while (!q.empty() && q.back().v >= A[i])
            q.pop_back();
        q.push_back(T(i, A[i]));
    }
    cout << q.front().v << endl;
    q.clear();
    for (int i = 0; i < n; i++)
    {
        if (i >= k)
        {
            if (q.front().idx + k < i)
                q.pop_front();
            cout << q.front().v << " ";
        }
        while (!q.empty() && q.back().v <= A[i])
            q.pop_back();
        q.push_back(T(i, A[i]));
    }
    cout << q.front().v << endl;
#ifdef _MSC_VER
    cin >> ws;
#endif
    return 0;
}

by Steinway @ 2018-07-27 16:25:09

...你们这个写的好简单啊..
(感觉自己就是个蒟蒻)


by andyli @ 2018-07-27 16:29:07

@Steinway 好简单才90分


by Steinway @ 2018-07-27 16:29:39

@andyli 也许是细节问题 你可以看看我博客第一篇


by CodeRikka @ 2018-07-27 17:17:24

这题不是单调栈单调队列水题吗?关系注意一下就行了啊。


by G_A_TS @ 2019-02-11 22:06:09

我也是90QwQ


by G_A_TS @ 2019-02-11 22:06:20

同WA3


by 猪龙骨丶丶 @ 2020-09-08 20:06:24

k=1


|