BZOJ 1012 最大数maxnumber 线段树
题目链接:
https://www.lydsy.com/JudgeOnline/problem.php?id=1012
题目大意:
见链接
思路:
直接用线段树模拟一下就可以了。
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);//不可再使用scanf printf
#define Max(a, b) ((a) > (b) ? (a) : (b))//禁用于函数,会超时
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Mem(a) memset(a, 0, sizeof(a))
#define Dis(x, y, x1, y1) ((x - x1) * (x - x1) + (y - y1) * (y - y1))
#define MID(l, r) ((l) + ((r) - (l)) / 2)
#define lson ((o)<<1)
#define rson ((o)<<1|1)
#pragma comment(linker, "/STACK:102400000,102400000")//栈外挂
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} typedef long long ll;
const int maxn = + ;
const int maxm = + ;
const int mod = ;//const引用更快,宏定义也更快
const int INF = ;
struct node
{
ll l, r, x;
}tree[maxn];
void build(int o, ll l, ll r)
{
tree[o].l = l, tree[o].r = r;
if(l == r)return;
ll m = MID(l, r);
build(lson, l, m);
build(rson, m + , r);
}
ll p, v;
void update(int o)
{
if(tree[o].l == tree[o].r)
{
tree[o].x = v;
return;
}
if(p <= tree[lson].r)update(lson);
else update(rson);
tree[o].x = Max(tree[lson].x, tree[rson].x);
}
ll ql, qr;
ll ans;
void query(int o)
{
if(ql <= tree[o].l && qr >= tree[o].r)
{
ans = Max(ans, tree[o].x);
return;
}
if(ql <= tree[lson].r)query(lson);
if(qr >= tree[rson].l)query(rson);
}
int main()
{
ll n, d;
scanf("%lld%lld", &n, &d);
build(, , n);
p = ;
ll t = , x;
char s[];
while(n--)
{
scanf("%s%lld", s, &x);
if(s[] == 'A')
{
v = t + x;
v %= d;
update();
p++;
}
else
{
ql = p - x;
qr = p - ;
ans = ;
query();
t = ans;
printf("%lld\n", ans);
}
}
return ;
}
BZOJ 1012 最大数maxnumber 线段树的更多相关文章
- BZOJ 1012: [JSOI2008]最大数maxnumber 线段树
题目链接:http://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: 13081 Solved: 5654[Subm ...
- 【BZOJ 1012】 [JSOI2008]最大数maxnumber(线段树做法)
[题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1012 [题意] [题解] 预开一个20W长度的线段树; 这里a[1..20W]={0} ...
- 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 MB Submit: 6542 Solve ...
- BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 8748 Solved: 3835[Submi ...
- 【单调栈】Bzoj 1012: 最大数maxnumber
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 6255 Solved: 2676[Submi ...
- BZOJ 1012 最大数maxnumber
Description 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作.语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度. 2. ...
随机推荐
- OpenGL绘制一个三角形
应该建立一个vertex shader文件和一个pixel shader文件,分别命名为shader.vsh和shader.fsh. shader.vsh: attribute vec3 positi ...
- apache Header set Cache-Control
设置静态页面的缓存最大值 在.htaccess中添加下面的代码 <FilesMatch "\.(flv|gif|jpg|jpeg|png|ico|swf)$"> Hea ...
- Java中InputStream 、 InputStreamReader 、 BufferedReader的区别
1.InputStream.OutputStream 处理字节流的抽象类 InputStream 是字节输入流的所有类的超类,一般我们使用它的子类,如FileInputStream等. OutputS ...
- vue指令示例合集
vue所有指令练习合集.这是个html文件,用chrome打开可查看结果. <!DOCTYPE html> <html lang="en" xmlns:v-on= ...
- Win10安装docker步骤
最近使用docker部署spring boot项目,写篇文章记录下步骤. 1. 确保本机win10系统虚拟化已启动启动,否则需要去BIOS设置(方法可百度) 2. 到docker网站下载DockerT ...
- C# 按部门拆分excel文件
按照所属部门不同将excel文件拆分成多个文件 string excel_path = @"G:\zhyue\backup\2018-08-01 读取腾讯邮箱接口-获取一个月内未接收到外部邮 ...
- Android学习笔记(4)----Rendering Problems(The graphics preview in the layout editor may not be accurate)
在Android Studio中新建了一个 setting.xml 文件,布局好文件后,从 Text 界面切换到 Design 界面,显示了如下错误: 网上搜寻 The graphics previe ...
- Recovering InnoDB table from an .ibd file.
Recovering an InnoDB table from only an .ibd file. Sometime you may need to recover a table when all ...
- js重名的处理
### 关于重名的处理 > 在变量提升阶段,如果名字重复了,不会重新的进行声明,但是会重新的进行定义(后面赋的值会把前面赋的值给替换掉) ```javascript //=>变量提升:fn ...
- xcopy-参数详解
XCOPY——目录复制命令 1.功能:复制指定的目录和目录下的所有文件连同目录结构. 2.类型:外部命令 3.格式:XCOPY [源盘:]〈源路径名〉[目标盘符:][目标路径名][/S][/V][/E ...