BZOJ 1012 单调队列+二分

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

//By SiriusRen
#include <cstdio>
#include <algorithm>
using namespace std;
#define int long long
int 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);
        }
    }
}

这里写图片描述

转载于:https://www.cnblogs.com/SiriusRen/p/6532235.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值