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. ...
随机推荐
- ASP.NET-三种认证Authentication简介
ASP.NET 的 认证Authentication主要分为三种 1.Form Authentication 用于互联网的认证,自定性强,功能强大,可以用cookie和ssl 2.Window A ...
- 【原创】Zend Framework 2框架之MVC
ZendFramework 2框架之MVC 作者:sys(360电商技术组) 1.前言 Zend Framework 2是zend官方推出的php开源框架,基于php5.3.他全然採用面向对象的代码实 ...
- jquery outerHeight方法 outerWidth方法 获取元素实际宽度高度
曾经写代码中,每当须要获取元素的实际"宽度"(这里的宽度是指元素宽度加上其边距)时,都须要用元素宽度加上margin值才行,今天发现一个叫outerWidth(options)的方 ...
- Elasticsearch yellow 意味着主分片可用,副本不可用
摘自:http://unasm.com/2016/11/644/ 在通过 /_cluster/state 命令查看es 状态的时候,发现es 处于一个yellow的状态, 这个很奇怪,按照官方的解释, ...
- ORA-00980:synonym translation is no longer valid
今天要把测试环境DB的数据更新成最新Production环境的数据,期间发生了一些问题: 1.首先从正式环境exp出想要用户的dmp档 2.drop掉测试环境底下相应用户 3.create测试环境底下 ...
- CentOS7设置中文输入法
转自:https://i.cnblogs.com/EditPosts.aspx?postid=8327755&update=1 CentOS7设置中文输入法 安装CentOS7之后,鼓捣了半天 ...
- Linux就该这么学 20181003(第四章Vim/shell/测试条件)
参考链接https://www.linuxprobe.com/ vim文本编辑器 命令模式:控制光标移动,可对文本进行复制,黏贴,删除和查找工作 输入模式:正常的文本录入 末行模式:保存或退出文档,以 ...
- hexo创建的tags和categories页面为空的解决办法
title: hexo创建的tags和categories页面为空的解决办法 toc: false date: 2018-04-16 02:26:10 主题:landscape 添加type以及men ...
- Codeforces 677D Vanya and Treasure 暴力+BFS
链接 Codeforces 677D Vanya and Treasure 题意 n*m中有p个type,经过了任意一个 type=i 的各自才能打开 type=i+1 的钥匙,最初有type=1的钥 ...
- application和javaBean练习
编写一个jsp程序,实现将用户信息保存在application对象的用户注册 package com.sp.test; public class User { private String usena ...