【BZOJ 1012】 [JSOI2008]最大数maxnumber

来源:互联网 发布:淘宝如何设置冰点促销 编辑:程序博客网 时间:2024/06/06 00:05

以前看过这个题 这次一遍A 真舒服

留下最大值 每次二分就行

#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>#define LL long longusing namespace std;LL a[200000+1],b[200000+1];LL n,MO;LL tot=1;int main(){//  fre0open("a.in","r",stdin);    cin>>n>>MO;LL tmp=0;    int cnt=0;    for(int i=1;i<=n;i++)    {        char c;getchar();c=getchar();        if(c=='A')        {            LL x;scanf("%lld",&x);x+=tmp;x%=MO;            while(a[tot]<=x&&tot>0) tot--;            a[++tot]=x;            b[tot]=++cnt;        }        else         {            LL x;scanf("%d",&x);            x=cnt-x+1;//cout<<a[1]<<' '<<a[2]<<endl;            int L=1,R=tot;             while(L<R)            {                int mid=(L+R)/2;                if(b[mid]<x) L=mid+1;                else R=mid;            }            tmp=a[L];            printf("%lld\n",tmp);        }            }        return 0;}
0 0
原创粉丝点击