BZOJ 1012 单调队列+二分

来源:互联网 发布:一级域名怎么解析二级 编辑:程序博客网 时间:2024/05/16 16:09

思路:
维护一个单减的序列 序号是单增的 每回二分查找第一个比询问的大的值
我手懒 用得lower_bound

//By SiriusRen#include <cstdio>#include <algorithm>using namespace std;#define int long longint m,mod,top,jy,ans,tot;char ch[3];struct Node{int pos,weight;}node[200050],t;bool operator < (Node a,Node b){    return a.pos<b.pos;}signed main(){    scanf("%lld%lld",&m,&mod);    for(int i=1;i<=m;i++){        scanf("%s%lld",ch,&jy);        if(ch[0]=='A'){            tot++,jy=(jy+ans)%mod;            while(top&&node[top-1].weight<=jy)top--;            node[top].pos=tot,node[top++].weight=jy;        }        else{            t.pos=tot-jy+1;            ans=lower_bound(node,node+top,t)->weight;            printf("%lld\n",ans);        }    }}

这里写图片描述

0 0
原创粉丝点击