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. ...
随机推荐
- Mysql如何避免全表扫描的方法
在以下几种条件下,MySQL就会做全表扫描: 1>数据表是在太小了,做一次全表扫描比做索引键的查找来得快多了.当表的记录总数小于10且记录长度比较短时通常这么做. 2>没有合适用于 ON ...
- 阅读《Android 从入门到精通》(15)——数字时钟
数字时钟(DigitalClock) java.lang.Object; android.view.View; android.widget.TextView; android.widget.Digi ...
- Spring中@Transactional事务回滚(含实例具体解说,附源代码)
一.使用场景举例 在了解@Transactional怎么用之前我们必须要先知道@Transactional有什么用. 以下举个栗子:比方一个部门里面有非常多成员,这两者分别保存在部门表和成员表里面,在 ...
- Android开发工具---SQLiteManager插件
Android开发工具---SQLiteManager插件 效果图例如以下: 平时在开发过程中查看数据库都要把数据库文件导出来,然后再用其它工具打开,SQLiteManager插件则给予我们一些便利. ...
- Sping框架中的注解详解
传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点:1.如果所有的内容都配置在.xml文件中,那么.xml文件将会十分庞大:如果按需求分开.xml文件 ...
- kafka 0.11 spark 2.11 streaming例子
""" Counts words in UTF8 encoded, '\n' delimited text received from the network every ...
- String转换成int型
private boolean judge(String str){ int year = 0; try{ year = Integer.valueOf(str).intValue(); }catch ...
- Codeforces 676E The Last Fight Between Human and AI 规律
链接 Codeforces 676E The Last Fight Between Human and AI 题意 给一个多项式,有些系数不确定.人和机器轮流填系数,系数可以是任何数,问是否能使得最后 ...
- 访问Storm ui界面,出现org.apache.storm.utils.NimbusLeaderNotFoundException: Could not find leader nimbus from seed hosts ["master"]. Did you specify a valid list of nimbus hosts for confi的问题解决(图文详解)
不多说,直接上干货! 前期博客 apache-storm-0.9.6.tar.gz的集群搭建(3节点)(图文详解) apache-storm-1.0.2.tar.gz的集群搭建(3节点)(图文详解)( ...
- DF标志和串传送指令
DF标志和串传送指令 flag的第10位是DF,方向标志位.在串处理指令中,控制si.di的递减. df = 0 每次操作后si.di递增 df = 1 每次操作后si.di递减 串传送指令 格式1: ...