BZOJ 1012: [JSOI2008]最大数maxnumber 单调栈
来源:互联网 发布:淘宝网账号登录历史 编辑:程序博客网 时间:2024/06/05 19:52
单调栈
1012: [JSOI2008]最大数maxnumber
Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 4988 Solved: 2252
[Submit][Status][Discuss]
Description
现在请求你维护一个数列,要求提供以下两种操作: 1、 查询操作。语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值。限制:L不超过当前数列的长度。 2、 插入操作。语法:A n 功能:将n加上t,其中t是最近一次查询操作的答案(如果还未执行过查询操作,则t=0),并将所得结果对一个固定的常数D取模,将所得答案插入到数列的末尾。限制:n是非负整数并且在长整范围内。注意:初始时数列是空的,没有一个数。
Input
第一行两个整数,M和D,其中M表示操作的个数(M <= 200,000),D如上文中所述,满足(0
Output
对于每一个查询操作,你应该按照顺序依次输出结果,每个结果占一行。
Sample Input
5 100
A 96
Q 1
A 97
Q 1
Q 2
A 96
Q 1
A 97
Q 1
Q 2
Sample Output
96
93
96
93
96
HINT
Source
/* ***********************************************Author :CKbossCreated Time :2015年05月12日 星期二 23时35分49秒File Name :BZOJ1012.cpp************************************************ */#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <string>#include <cmath>#include <cstdlib>#include <vector>#include <queue>#include <set>#include <map>using namespace std;const int maxn=200200;int a[maxn],b[maxn],top;int n,d,x,t;char cmd[5];int find(int x) {int low=0,mid,high=top-1;int ans=-1;while(low<=high){mid=(low+high)/2;if(b[mid]<x) low=mid+1;else { ans=mid; high=mid-1; }}return a[ans];}int main(){//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);scanf("%d%d",&n,&d);int k=1;for(int i=0;i<n;i++){scanf("%s%d",cmd,&x);if(cmd[0]=='A'){x=(x+t)%d;k++;while(top>0&&a[top-1]<x) top--;a[top]=x; b[top]=k; top++;}else if(cmd[0]=='Q'){t=find(k-x+1);printf("%d\n",t);}} return 0;}
0 0
- BZOJ 1012: [JSOI2008]最大数maxnumber 单调栈
- [BZOJ 1012][JSOI2008]最大数maxnumber:线段树|单调栈
- bzoj 1012: [JSOI2008]最大数maxnumber(单调栈+二分)
- BZOJ 1012 [JSOI2008]最大数maxnumber (单调栈)
- BZOJ 1012([JSOI2008]最大数maxnumber-单调队列)
- 【BZOJ 1012】 [JSOI2008]最大数maxnumber(单调队列做法)
- BZOJ 1012: [JSOI2008]最大数maxnumber 单调队列/线段树
- BZOJ 1012 JSOI2008 最大数maxnumber 单调栈+二分 / 线段树
- 【单调栈】Bzoj 1012: 最大数maxnumber
- 【单调队列】1012: [JSOI2008]最大数maxnumber
- [JSOI2008] [BZOJ1012] 最大数maxnumber - 单调栈
- [BZOJ1012][JSOI2008]最大数maxnumber-单调栈
- 1012: [JSOI2008]最大数maxnumber 单调栈+二分
- BZOJ 1012: [JSOI2008]最大数maxnumber
- BZOJ 1012 [JSOI2008]最大数maxnumber
- BZOJ 1012: [JSOI2008]最大数maxnumber
- [BZOJ 1012][JSOI2008]最大数maxnumber
- BZOJ 1012: [JSOI2008]最大数maxnumber
- android目录路径获取
- IOS 控件之基础整理
- IPv6 NAT-PT静态映射
- I.MX6Q(TQIMX6Q/TQE9)学习笔记——新版BSP之网卡驱动移植
- java从菜鸟到架构师的必看书籍
- BZOJ 1012: [JSOI2008]最大数maxnumber 单调栈
- Android内存分析工具
- 安装spyder python时 出现的问题
- C++中特殊的成员变量的初始化方法
- hdu 3037(Lucas定理,大组合数取模)
- java异常笔记
- poj 1077 Eight (BFS)
- 2014届第一场排位赛
- myBatis学习笔记(8)—— 一级缓存&二级缓存