bzoj1012: [JSOI2008]最大数maxnumber(貌似是道线段树喔)
1012: [JSOI2008]最大数maxnumber
题目:传送门
题解:
发现自己空了一道水题...
1~210000建线段树,其实就是一道裸题...
单点修改+区间查询...1A~
代码:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define qread(x)x=read();
using namespace std;
inline int read()
{
int f=,x=;char ch;
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return f*x;
}
struct node
{
int l,r,lc,rc,c;
}tr[];int len;
void bt(int l,int r)
{
len++;int now=len;
tr[now].l=l;tr[now].r=r;tr[now].c=;
tr[now].lc=tr[now].rc=-;
if(l<r)
{
int mid=(l+r)/;
tr[now].lc=len+;bt(l,mid);
tr[now].rc=len+;bt(mid+,r);
}
}
void change(int now,int x,int k)
{
if(tr[now].l==tr[now].r){tr[now].c=k;return ;}
int lc=tr[now].lc,rc=tr[now].rc;
int mid=(tr[now].l+tr[now].r)/;
if(x<=mid)change(lc,x,k);
else if(mid+<=x) change(rc,x,k);
tr[now].c=max(tr[lc].c,tr[rc].c);
}
int findmax(int now,int l,int r)
{
if(l==tr[now].l && tr[now].r==r)return tr[now].c;
int lc=tr[now].lc,rc=tr[now].rc;
int mid=(tr[now].l+tr[now].r)/;
if(r<=mid)return findmax(lc,l,r);
else if(mid+<=l)return findmax(rc,l,r);
else return max(findmax(lc,l,mid),findmax(rc,mid+,r));
}
int main()
{
int M,D,t=,ans,num;
qread(M);qread(D);
char c[];len=;
bt(,);num=;
for(int i=;i<=M;i++)
{
int x;
scanf("%s",c);qread(x);
if(c[]=='A')
change(,++num,(x+t)%D);
else
{
t=findmax(,num-x+,num);
printf("%d\n",t);
}
}
return ;
}
bzoj1012: [JSOI2008]最大数maxnumber(貌似是道线段树喔)的更多相关文章
- 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: 8748 Solved: 3835[Submi ...
- 【听说是线段树】bzoj1012 [JSOI2008]最大数maxnumber
一眼看题目吓了一跳:这TM不就是单调队列吗,200000又怎样,大不了我二分嘛 系统提示:成功开启 手残模式 开始瞎写: #include <cstdio> ]; ]; int m,mod ...
- BZOJ1012 [JSOI2008]最大数maxnumber
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...
- [BZOJ1012] [JSOI2008] 最大数maxnumber (ST表)
Description 现在请求你维护一个数列,要求提供以下两种操作:1. 查询操作.语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度.2. 插 ...
- BZOJ1012——[JSOI2008]最大数maxnumber
1.题目大意:求末尾L个数的最大值,强制在线 2.分析:这个拿线段树可以直接水过,然后我写了一个 维护单调栈, 二分求最大值的短代码,手懒.... #include <cstdio> #i ...
- BZOJ1012[JSOI2008]最大数maxnumber 题解
题目大意: 维护一个数列,有两种操作:1. 查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度.2.插入操作:将n加上t,其中t是最近一次查询操作的答案(如果还未执行 ...
- [bzoj1012](JSOI2008)最大数maxnumber(Fenwick Tree)
Description 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作.语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度. 2. ...
- BZOJ1012:[JSOI2008]最大数maxnumber(线段树)
Description 现在请求你维护一个数列,要求提供以下两种操作:1. 查询操作.语法:Q L 功能:查询当前数列中末尾L 个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度.2. ...
随机推荐
- .C#-NET开源方向基本
我的理解,nancyFx是一个.net的微型框架,可以在Linux环境下运行,ServiceStack也是全平台框架,更大一些 owin的概念:Open Web Server Interface Fo ...
- 【原创】PHP扩展开发进阶
PHP扩展开发进阶 作者:wf (360电商技术) 在第一期PHP扩展开发入门中,简单的介绍了PHP的总体架构和执行机制,并具体说明了怎样开发和编译一个主要的PHP扩展,最后在PHP 5.3的环境下 ...
- POJ 2447
挺水的一题.其实只要理解了RSA算法,就知道要使用大整数分解的方法来直接模拟了. 不过,要注意两个INT64的数相乘来超范围 #include <iostream> #include &l ...
- 14、反射(reflect)
一.反射概念 不用实例化也可以调用类中的私有成员:反射慢,实例化快:反射可以看到其他类中的内部构造,透明,但是不安全. JAR:JAVA函数库 WAR:web发布的包 YAR:RPC服务 二.idea ...
- 解题报告 之 HDU5317 RGCDQ
解题报告 之 HDU5317 RGCDQ Description Mr. Hdu is interested in Greatest Common Divisor (GCD). He wants to ...
- 110个经常使用Oracle函数总结
1. ASCII 返回与指定的字符相应的十进制数; SQL> select ascii(A) A,ascii(a) a,ascii(0) zero,ascii( ) space from dua ...
- Educational Codeforces Round 6 B. Grandfather Dovlet’s calculator 暴力
B. Grandfather Dovlet’s calculator Once Max found an electronic calculator from his grandfather Do ...
- 集群节点Elasticsearch升级
集群节点Elasticsearch升级 操作流程 1.首先执行Elasticsearch-1.2.2集群的索引数据备份 2.关闭elasticsearch-1.2.2集群的recovery.compr ...
- SpringMVC+Spring+Hibernate框架整合原理,作用及使用方法
转自:https://blog.csdn.net/bieleyang/article/details/77862042 SSM框架是spring MVC ,spring和mybatis框架的整合,是标 ...
- Java 以空格分割字符串
Java中使用类似于 str.split("/"); 的方法可以很方便的实现将一个字符串分割为数组, 但是如果分隔符是一个(或几个)空格呢?? 我们的本能反应或许应该是 str.s ...