bzoj1012 maximum number maxnumber - monotonic stack

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

Monotone stack water problem; used lower_bound for two points.

code show as below:

#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] = only;
        }
        else
        {
            int k=lower_bound(sta+ 1 ,sta+top+ 1 ,len-x+ 1 )-sta; // The bisection position in the stack 
            lst= a[sta[k]];
            printf("%d\n",lst);
        }
    }
    return 0;
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325055185&siteId=291194637