BZOJ 1012 [JSOI2008]最大数maxnumber【线段树】
水题,每次记录一下当前有多少个数,然后按照题目所指示的那样模拟就行,每次向线段树末尾插入(其实是修改)题目中指定的数,然后询问当前的个数到前面Q个数中最大值是多少结果就是,好久不碰线段树了,用数组模拟线段树时数组要开大4倍,一开始没发现这点贡献了好多runtime_error TAT
#include<iostream>
#include<cstdio>
#include <math.h>
using namespace std;
int d;
int max(int a,int b)
{
if(a>=b)return a;else return b;
}
void insert(int node,int l,int r,int po,intvalue,int m[])
{
int mid=(l+r)>>1;
if (l+1==r){m[node]=value;return;}
else
{
if (po<=mid)insert(node*2,l,mid,po,value,m);
else insert(node*2+1,mid,r,po,value,m);
}
m[node]=max(m[node*2],m[node*2+1]);
}
int search(int node,int l,int r,int lq,intrq,int m[])
{
int mid = (l+r)>>1,temp=0;
if ((lq<=l)&&(r<=rq))return m[node];
if(lq<mid)temp=max(temp,search(node*2,l,mid,lq,rq,m));
if(rq>mid)temp=max(temp,search(node*2+1,mid,r,lq,rq,m));
returntemp;
}
int main()
{
int m,t,n[800001]={0},len=0,ans=0,ans_array[200001]={0},h=0;
char ch[5];
scanf("%d%d",&m,&d);
for (inti=1;i<=m;i++)
{
scanf("%s %d",ch,&t);
if (ch[0]=='A')
{
len++;
insert(1,0,m,len,(t+ans)%d,n);
}
if (ch[0]=='Q')
{
ans=search(1,0,m,len-t,len,n);
h++;
ans_array[h]=ans;
}
}
for (int i=1;i<=h;i++)printf("%d\n",ans_array[i]);
return 0;
}
BZOJ 1012 [JSOI2008]最大数maxnumber【线段树】的更多相关文章
- bzoj 1012: [JSOI2008]最大数maxnumber (线段树)
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 13081 Solved: 5654[Subm ...
- BZOJ 1012: [JSOI2008]最大数maxnumber 线段树
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1012 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作.语法:Q L 功能: ...
- bzoj-1012 1012: [JSOI2008]最大数maxnumber(线段树)
题目链接: 1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MB Description 现在请求你维护一个数列,要 ...
- 1012: [JSOI2008]最大数maxnumber 线段树
https://www.lydsy.com/JudgeOnline/problem.php?id=1012 现在请求你维护一个数列,要求提供以下两种操作:1. 查询操作.语法:Q L 功能:查询当前数 ...
- 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: 4750 Solved: 2145[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: 8748 Solved: 3835[Submi ...
- 【BZOJ 1012】 [JSOI2008]最大数maxnumber(线段树做法)
[题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1012 [题意] [题解] 预开一个20W长度的线段树; 这里a[1..20W]={0} ...
随机推荐
- shell中的-z
-z 字符串为"null",即是指字符串长度为零.
- 严重:The web application [web01] appears to have started a thread named ...
Tomcat报错 严重:The web application [web01] appears to have started a thread named [PooledThread-1] but ...
- ThreadLocal应用场景以及源码分析
一.应用篇 ThreadLocal介绍 ThreadLocal如果单纯从字面上理解的话好像是“本地线程”的意思,其实并不是这个意思,只是这个名字起的太容易让人误解了,它的真正的意思是线程本地变量. 实 ...
- SQL中的动态语句执行--exec(@sqlstr)
begin drop table #tmptable declare @money ut_money set @money=1.2345 create table #tmptable ( je ut_ ...
- 覆盖alert对话框-自制Jquery.alert插件
Javascript 代码: (function ($) { 'use strict'; window.alert = $.alert = function (msg) { var defaultOp ...
- OpenGL Frustum参数设置
opengl中使用Frustum来设置透视投影,函数原型: frustum(float left, float right, float buttom, float top, float near, ...
- 签名ipa,让其它手机也安装
开发的时候,需要将app让其它人装上测试,虽然通过xcode可以使用编译进去,但是仍显不方便. 网上有个工具, http://code.google.com/p/iresign/ 通过这个工具,使用自 ...
- DRBD+NFS+Keepalived高可用环境
1.前提条件 准备两台配置相同的服务器 2.安装DRBD [root@server139 ~]# yum -y update kernel kernel-devel [root@server139 ~ ...
- js正则函数match、exec、test、search、replace、split使用集合
match 方法 使用正则表达式模式对字符串执行查找,并将包含查找的结果作为数组返回. stringObj.match(rgExp) 参数 stringObj 必选项.对其进行查找的 String 对 ...
- 安装ruby开发环境
如何快速正确的安装 Ruby, Rails 运行环境 对于新入门的开发者,如何安装 Ruby, Ruby Gems 和 Rails 的运行环境可能会是个问题,本页主要介绍如何用一条靠谱的路子快速安装 ...