其他分享
首页 > 其他分享> > 单调队列模板

单调队列模板

作者:互联网

a[n + 1] = t = 0;
long long area = 0;
for(int i = 1; i <= n + 1; i++) {
    if(a[i] > s[t]) s[++t] = a[i], w[t] = 1;
    else {
        int width = 0;
        while(a[i] < s[t]) {
            width += w[t];
            area = max(area, (long long)width * s[t]);
            t--;
        }
        width++;
        s[++t] = a[i], w[t] = width;
    }
}

 

标签:area,队列,max,++,long,width,int,模板,单调
来源: https://www.cnblogs.com/9r2pqvv88/p/16462744.html