1012: [JSOI2008]最大数maxnumber
单点更新,区间求最大值的题;
可以使用树状数组和线段树;
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 2000009
#define ll long long
using namespace std; int m,n=;
ll ma[maxn],d[maxn]; void insert(int w,ll x)
{
d[w]=x;
while(w<=m)
{
ma[w]=max(ma[w],x);
w+=w&-w;
}
} ll query(int l,int r)
{
ll ret=d[r];
while(l<=r)
{
int cnt=r&-r;
ret=max(ret,d[r]);
if(r-cnt+>=l)
{
ret=max(ret,ma[r]);
r-=r&-r;
}
else r--;
}
return ret;
} char s[];
ll x,mod; int main()
{
ll t=;
scanf("%d%lld",&m,&mod);
for(int i=;i<m;i++)
{
scanf("%s",s);
if(s[]=='A')
{
scanf("%d",&x);
++n;
insert(n,(x+t)%mod);
}
else
{
scanf("%d",&x);
t=query(n-x+,n);
printf("%lld\n",t);
}
}
return ;
}
1012: [JSOI2008]最大数maxnumber的更多相关文章
- 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 现在请求你维护一个数列,要 ...
- BZOJ——1012: [JSOI2008]最大数maxnumber || 洛谷—— P1198 [JSOI2008]最大数
http://www.lydsy.com/JudgeOnline/problem.php?id=1012|| https://www.luogu.org/problem/show?pid=1198 T ...
- 【BZOJ】1012: [JSOI2008]最大数maxnumber(树状数组+rmq)
http://www.lydsy.com/JudgeOnline/problem.php?id=1012 树状数组原来我只懂得sum和add的操作,今天才知道可以有求区间最值的操作,我学习了一下写了个 ...
- bzoj 1012 [JSOI2008]最大数maxnumber
原题链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1012 线段树,单点更新.. #include<algorithm> #incl ...
- BZOJ 1012: [JSOI2008]最大数maxnumber 线段树
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1012 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作.语法:Q L 功能: ...
- 【BZOJ】1012: [JSOI2008]最大数maxnumber 树状数组求区间最值
题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1012 题意:维护一个数列,开始时没有数值,之后会有两种操作, Q L :查询数列末 ...
随机推荐
- win7 cmd命令行窗口 宽度无法变大 自由调整大小
偶然遇到了这个问题,百度查到了解决方案,执行一个bat批处理命令. mode con lines=40 mode con cols=160 color 250 cls @cmd
- Java .Net C++ RSA 加密
原文:http://www.codeproject.com/Articles/25487/Cryptographic-Interoperability-Keys DEMO: JAVA .Net C++
- Html5 Video 实现方案
来源:http://ask.dcloud.net.cn/article/569 源码下载 前言: 最近项目中需要用到html5 视频播放功能,于是稍微研究了解了下,遇到了很多坑,特此记录下. 一. H ...
- RTTI和反射
JAVA 运行时识别对象和类的信息,主要有两种方式:一种是传统的RTTI,它假定我们在编译时已经知道了所有的类型:另一种是"反射"机制,它允许我们在运行时发现和使用类的信息. 参考 ...
- oracle中的exists 和not exists 用法 in与exists语句的效率问题
博文来源(oracle中的exists 和not exists 用法):http://chenshuai365-163-com.iteye.com/blog/1003247 博文来源( in与exi ...
- Java的基础概念
JDK (Java Development Kit) Java Developer Kit contains tools needed to develop the Java programs, an ...
- OC5_NSMutableString操作
// // main.m // OC5_NSMutableString操作 // // Created by zhangxueming on 15/6/10. // Copyright (c) 201 ...
- angular2 select change 事件
刚开始这是啥?(wrong!!! change事件会在 选择option行为 之前执行prodDirId,是取不到选择后正确的id值的,取得是选择行为前prodDirId的值(有试过setTi ...
- 修改虚机IP
同网段的话,直接修改,不同网段的话,使用以下方法: 步骤一:nova list --all-tenant 找到相应虚拟机+--------------------------------------+ ...
- LIS
五:LIS 概念 最长上升子序列(Longest Increasing Subsequence,LIS),在计算机科学上是指一个序列中最长的单调递增的子序列.比如一个序列31 2 6 3 8,他的最长 ...