[JSOI2008]最大数maxnumber
[JSOI2008]最大数maxnumber
标签: 线段树 单独队列
题解
线段树裸题。
如果一直RE可能是你用的cin/cout。
Code
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,a) for(int i=start[(a)];i;i=e[i].next)
inline int read()
{
int sum=0,p=1;char ch=getchar();
while(!(('0'<=ch && ch<='9') || ch=='-'))ch=getchar();
if(ch=='-')p=-1,ch=getchar();
while('0'<=ch && ch<='9')sum=sum*10+ch-48,ch=getchar();
return sum*p;
}
const int maxn=2e5+20;
int n;
int mod;
struct node {
int mx;
inline void Merge(node a,node b)
{
mx=max(a.mx,b.mx);
}
};
node c[maxn*4];
void init()
{
n=read();mod=read();
}
#define lc (o<<1)
#define rc (o<<1 | 1)
#define left lc,l,mid
#define right rc,mid+1,r
inline void update(int x,int d,int o,int l,int r)
{
if(l==r)
{
c[o].mx=d;
return;
}
register int mid=(l+r)>>1;
if(x<=mid)update(x,d,left);
else update(x,d,right);
c[o].Merge(c[lc],c[rc]);
}
inline int query(int ql,int qr,int o,int l,int r)
{
if(ql<=l && r<=qr)
{
return c[o].mx;
}
register int mid=(l+r)>>1;register int ans=0;
if(ql<=mid)ans=max(ans,query(ql,qr,left));
if(qr>mid)ans=max(ans,query(ql,qr,right));
return ans;
}
inline void doing()
{
register int t=0;
int cnt=0;
REP(i,1,n)
{
char ch[5];int x;
scanf("%s",ch);
if(ch[0]=='A')
{
cnt++;
x=read();x=(x+t)%mod;
update(cnt,x,1,1,n);
}else
{
x=read();
t=query(cnt-x+1,cnt,1,1,n);
printf("%d\n",t);
}
}
}
int main()
{
init();
doing();
return 0;
}
[JSOI2008]最大数maxnumber的更多相关文章
- BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 8748 Solved: 3835[Submi ...
- BZOJ-1012[JSOI2008]最大数maxnumber 线段树区间最值
这道题相对简单下面是题目: 1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MB Submit: 6542 Solve ...
- 【bzoj1012】[JSOI2008]最大数maxnumber
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 8339 Solved: 3624[Submi ...
- Cogs 1844. [JSOI2008]最大数maxnumber
[JSOI2008]最大数maxnumber ★★ 输入文件:bzoj_1012.in 输出文件:bzoj_1012.out 简单对比 时间限制:3 s 内存限制:162 MB [题目描述] 现在请求 ...
- BZOJ 1012: [JSOI2008]最大数maxnumber【线段树单点更新求最值,单调队列,多解】
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 10374 Solved: 4535[Subm ...
- bzoj 1012: [JSOI2008]最大数maxnumber (线段树)
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 13081 Solved: 5654[Subm ...
- BZOJ 1012: [JSOI2008]最大数maxnumber 单调队列/线段树/树状数组/乱搞
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 4750 Solved: 2145[Submi ...
- 大视野 1012: [JSOI2008]最大数maxnumber(线段树/ 树状数组/ 单调队列/ 单调栈/ rmq)
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 9851 Solved: 4318[Submi ...
- bzoj-1012 1012: [JSOI2008]最大数maxnumber(线段树)
题目链接: 1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MB Description 现在请求你维护一个数列,要 ...
随机推荐
- Python解析JSON详解
JSON 函数 使用 JSON 函数需要导入 json 库:import json. 函数 描述 json.dumps 将 Python 对象编码成 JSON 字符串 json.loads 将已 ...
- 数据结构 链式哈希表(Hash Table)的接口定义与实现分析(完整代码)
链式哈希表的接口定义 关于哈希表与链式哈希表的描述可以参阅:http://www.cnblogs.com/idreamo/p/7990860.html 链式哈希表的操作与属性有:初始化.销毁.插入元素 ...
- X86寄存器全称
body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...
- java面向对象的三大特性——多态
多态 所谓多态就是指程序中定义的引用变量所指向的具体类型和通过该引用变量发出的方法调用在编程时并不确定,而是在程序运行期间才确定,即一个引用变量倒底会指向哪个类的实例对象,该引用变量发出的方法调用到底 ...
- linux_Nginx日志
错误信息日志配置: 日志文件默认:/application/nginx/logs/erroe.log error_log logs/error.log error; # 不写默认就有,默认error, ...
- ListCtrl控件
一 CListCtrl类型 LVS_EDITLABELS LVS_OWNERDRAWFIXED LVS_REPORT LVS_SHOWSELALWAYS LVS_SINGLESEL LVS_SMALL ...
- IO (一)
1 IO(Input Output)流概述 IO流用来处理设备之间的数据传输. java对数据的操作是通过流的方式. java用于操作流的对象都在IO包中. 流按操作数据分为两种:字节流和字符流. 流 ...
- Visionpro学习笔记 :QuickBuild-Based Application Run-Once Button
1) Creating a Run-Once Button 通过JobManager调用VisionPro文件.所有的过程放到一个Try/Catch块中. Private Sub RunOnceBut ...
- traffic server文件目录
功能: Trafficserver的主要功能是缓存,当然你也可以用它来做纯粹的反向代理(像通常用nginx那样).通常切入一个庞大的系统的最好方式是看如何使用,使用traffic server的主要入 ...
- Oracle-Linux安装配置python3.6环境
最近公司更换了linux系统的版本,从Ubuntu改为了oracle linux,相关的Python环境也要重新配置,记录一下基本配置的过程. 相关环境 系统:oracle linux7.3 系统自带 ...