首页 > 其他 > 详细

bzoj1012最大数maxnumber——单调栈

时间:2018-04-29 00:57:58      阅读:205      评论:0      收藏:0      [点我收藏+]

题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1012

单调栈水题;用了一下lower_bound二分。

代码如下:

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int m,d,len,a[200005],sta[200005],top,lst;
char s[5];
int main()
{
    scanf("%d%d",&m,&d);
    for(int i=1,x;i<=m;i++)
    {
        scanf("%s%d",&s,&x);
        if(s[0]==A)
        {
            a[++len]=(x+lst)%d;
            while(top&&a[sta[top]]<a[len])top--;
            sta[++top]=len;
        }
        else
        {
            int k=lower_bound(sta+1,sta+top+1,len-x+1)-sta;//在栈中二分位置 
            lst=a[sta[k]];
            printf("%d\n",lst);
        }
    }
    return 0;
}

 

bzoj1012最大数maxnumber——单调栈

原文:https://www.cnblogs.com/Zinn/p/8969959.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!