单调队列TLE了,有没有路过的巨佬?

P1440 求m区间内的最小值

蒟蒻CGZ @ 2020-06-21 23:10:02

单调队列大量一个模板,第二个点和最后一个点TLE(C++)

#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e6 + 10;
int head, tail, q[N], a[N], n, m;

int main() {
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for(int i = 1; i <= n; ++ i) 
        cin >> a[i];
    head = 1; tail = 0;
    for(int i = 1; i <= n; ++ i) {
        cout << a[q[head]] << endl;
        while(head <= tail && q[head] + m <= i) ++ head;
        while(head <= tail && a[i] < a[q[tail]]) -- tail;
        q[++ tail] = i;
    }
    return 0;
}

by 蒟蒻CGZ @ 2020-06-21 23:10:29

更正:打了一个模板


by B_1168 @ 2020-06-22 00:41:01

可以拿这个试一下


by DreamFox @ 2020-06-25 19:01:23

能过啊


by DreamFox @ 2020-06-25 19:02:16

This

我用STL中的deque


|