bzoj 1012: [JSOI2008]最大数maxnumber(单调栈+二分)

来源:互联网 发布:sqlserver删除表字段 编辑:程序博客网 时间:2024/06/16 07:31

单调栈维护下,二分就好了
bzoj用%I64d一直格式错误,换了%lld就好了

#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;typedef long long LL;const int MAXN = 200100;LL num[MAXN];int len;int s[MAXN];int t;int M;LL D,n,pre;int main(){    char op;    scanf("%d %lld",&M,&D);    for(int i = 0; i < M; ++i)    {        scanf(" %c %lld",&op,&n);        if(op == 'Q')        {            int index = len-n;            index = lower_bound(s,s+t,index)-s;            pre = num[s[index]];            printf("%lld\n",num[s[index]]);        }        else        {            n = (n+pre)%D;            num[len++] = n;            while(t > 0 && num[s[t-1]] <= num[len-1])                --t;            s[t++] = len-1;        }    }    return 0;}
阅读全文
0 0
原创粉丝点击