【BZOJ】【1012】【JSOI2008】最大数maxnumber
线段树
……现在再来看这题感觉好水啊,当年的大老虎现在也变成小花猫了,真是令人感动<_<
/**************************************************************
Problem: 1012
User: Tunix
Language: C++
Result: Accepted
Time:768 ms
Memory:4396 kb
****************************************************************/ //BZOJ 1012
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
#define pb push_back
using namespace std;
inline int getint(){
int v=,sign=; char ch=getchar();
while(ch<''||ch>''){ if (ch=='-') sign=-; ch=getchar();}
while(ch>=''&&ch<=''){ v=v*+ch-''; ch=getchar();}
return v*sign;
}
const int N=2e5+,INF=~0u>>;
typedef long long LL;
/******************tamplate*********************/
int n,m,D;
int t[N<<];
#define L (o<<1)
#define R (o<<1|1)
#define mid (l+r>>1)
void update(int o,int l,int r,int pos,int val){
if (l==r) t[o]=val;
else{
if(pos<=mid) update(L,l,mid,pos,val);
else update(R,mid+,r,pos,val);
t[o]=max(t[L],t[R]);
}
}
int ql,qr;
int query(int o,int l,int r){
if (ql<=l && qr>=r) return t[o];
else{
int ans=;
if (ql<=mid) ans=max(ans,query(L,l,mid));
if (qr>mid) ans=max(ans,query(R,mid+,r));
return ans;
}
}
int main(){
#ifndef ONLINE_JUDGE
freopen("1012.in","r",stdin);
freopen("1012.out","w",stdout);
#endif
n=getint(); D=getint();
int t=,x,ed=;
char cmd[];
F(i,,n){
scanf("%s",cmd); x=getint();
if (cmd[]=='Q'){
ql=ed-x+; qr=ed;
t=query(,,n);
printf("%d\n",t);
}else{
++ed;
update(,,n,ed,(x+t)%D);
}
}
return ;
}
1012: [JSOI2008]最大数maxnumber
Time Limit: 3 Sec Memory Limit: 162 MB
Submit: 4827 Solved: 2184
[Submit][Status][Discuss]
Description
现
在请求你维护一个数列,要求提供以下两种操作: 1、 查询操作。语法:Q L
功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值。限制:L不超过当前数列的长度。 2、 插入操作。语法:A n
功能:将n加上t,其中t是最近一次查询操作的答案(如果还未执行过查询操作,则t=0),并将所得结果对一个固定的常数D取模,将所得答案插入到数列的
末尾。限制:n是非负整数并且在长整范围内。注意:初始时数列是空的,没有一个数。
Input
第一行两个整数,M和D,其中M表示操作的个数(M <= 200,000),D如上文中所述,满足(0
Output
对于每一个查询操作,你应该按照顺序依次输出结果,每个结果占一行。
Sample Input
A 96
Q 1
A 97
Q 1
Q 2
Sample Output
93
96
HINT
Source
【BZOJ】【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 ...
- 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
原题链接: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【线段树】
水题,每次记录一下当前有多少个数,然后按照题目所指示的那样模拟就行,每次向线段树末尾插入(其实是修改)题目中指定的数,然后询问当前的个数到前面Q个数中最大值是多少结果就是,好久不碰线段树了,用数组模拟 ...
- 【单调队列+二分查找】bzoj 1012: [JSOI2008]最大数maxnumber
[题意] 维护一个单调递减的q数组,用id数组记录q数组的每个下标对应在原数组的位置,那么id数组一定有单调性(q数组中越靠后,原数组中也靠后),然后二分查找这个数 [AC] #include< ...
- 大视野 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 现在请求你维护一个数列,要 ...
随机推荐
- project 2010 使用技巧
快捷键 设置任务子任务 ALT+SHIFT+向右方向键 1.工作时间设置 新建一个日历后,可以在 “项目 >> 项目信息 >> 日历” 中进行选择
- JS中cookie的基本使用
cookie是本身是HTML中ducument中的一个属性,可以用来保存一些简单的数据信息,比如用户名.密码等,提高一些网站的用户体验度.下面就来简单的说说cookie,它有下面几个特性: 1.有过期 ...
- input中如何输入逆写的中文句子
<input style="text-align:right" /><input type="text" dir="rtl" ...
- BufferedInputSream和BufferedOutputSream,,,
package cd.itcast.bufferinputstream; import java.io.BufferedInputStream; import java.io.File; import ...
- C# 多线程 简单使用方法以及常用参数
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- SQL Server 基础:Case两种用法
测试数据 1).等值判断->相当于switch case select S#,C#,C#=( case C# when 1 then '语文' when 2 then '数学' when 3 t ...
- 网页绘制图表 Google Charts with JavaScript #2 ....与ASP.NET网页结合 (ClientScriptManager.RegisterStartupScript 方法)
此为文章备份,原文出处(我的网站) 网页绘制图表 Google Charts with JavaScript #2 ....与ASP.NET网页结合 (ClientScriptManager.Regi ...
- Python 有哪些优点?为何要学Python?
1. 支持OOP编程 从根本上讲Python仍是一种面向对象的语言,支持多态.继承等高级概念,在Python里使用OOP十分容易 没有C++.Java那样复杂,但不必做Python下OOp高手,够 ...
- openSUSE13.1安装时要注意的问题(未完待续)
1.最好用官方给的imageWriter来写镜像,不要用UltraISO来写镜像,会导致安装Kaffein包错误(:)可能也会有别的错误),后来我用imageWriter写了之后就没有在安装时报错了
- postgresql 连接数
改文件 postgresql.conf 里的 #max_connections=32 为 max_connections=1024 以及另外相应修改 share_buffer 参数. 执行SELECT ...