P1440 求m区间的最小值

  一道单调区间(ST表过不了啊……)

  就是一个队列的模拟,不是很难理解。

  那就直接上代码啦:

#include<cstdio>
using namespace std;
int n,m,h[2000005][3],x;
int main()
{
    scanf("%d%d",&n,&m);
    printf("0
");
    int head=1,tail=1,x;
    scanf("%d",&x);
    h[tail][1]=1;//如果这句不写,用下下面的样例试试
    h[tail][2]=x;
    for(int i=2; i<=n; i++)
    {
        if(i-m>h[head][1])
            head++;
        printf("%d
",h[head][2]);
        scanf("%d",&x);
        while(h[tail][2]>x&&tail>=head)
            tail--;
        tail++;
        h[tail][1]=i;
        h[tail][2]=x;
    }
    return 0;
}
/*
3 2
6 7 8
*/
原文地址:https://www.cnblogs.com/popo-black-cat/p/10060595.html