题目链接:

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 线段树的更多相关文章

  1. BZOJ 1012: [JSOI2008]最大数maxnumber 线段树

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1012 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作.语法:Q L 功能: ...

  2. bzoj 1012: [JSOI2008]最大数maxnumber (线段树)

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 13081  Solved: 5654[Subm ...

  3. 【BZOJ 1012】 [JSOI2008]最大数maxnumber(线段树做法)

    [题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1012 [题意] [题解] 预开一个20W长度的线段树; 这里a[1..20W]={0} ...

  4. bzoj-1012 1012: [JSOI2008]最大数maxnumber(线段树)

    题目链接: 1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MB Description 现在请求你维护一个数列,要 ...

  5. 1012: [JSOI2008]最大数maxnumber 线段树

    https://www.lydsy.com/JudgeOnline/problem.php?id=1012 现在请求你维护一个数列,要求提供以下两种操作:1. 查询操作.语法:Q L 功能:查询当前数 ...

  6. BZOJ-1012[JSOI2008]最大数maxnumber 线段树区间最值

    这道题相对简单下面是题目: 1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MB Submit: 6542 Solve ...

  7. BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 8748  Solved: 3835[Submi ...

  8. 【单调栈】Bzoj 1012: 最大数maxnumber

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 6255  Solved: 2676[Submi ...

  9. BZOJ 1012 最大数maxnumber

    Description 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作.语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度. 2. ...

随机推荐

  1. mac下如何找到hosts文件(转)

    打开Finder 在菜单中选择[前往][前往文件夹] 或使用快捷键Command+Shift+G        进入跳转路径,输入: /private/etc/ 点击[前往]      即可找到hos ...

  2. 简单明了区分escape、encodeURI和encodeURIComponent(转)

    一.前言 讲这3个方法区别的文章太多了,但是大部分写的都很绕.本文试图从实践角度去讲这3个方法. 二.escape和它们不是同一类 简单来说,escape是对字符串(string)进行编码(而另外两种 ...

  3. GPUImage使用

    GPUImage项目下载地址:https://github.com/BradLarson/GPUImage.git 下载项目时如果下载不下来可以直接check一份(之前下载了好多次都是下载失败,最后没 ...

  4. 按照拼音排序的SQL语句条件

    ORDER BY nlssort(NAME, 'NLS_SORT=SCHINESE_PINYIN_M')

  5. 一文看懂大数据的技术生态圈,Hadoop,hive,spark都有了

    一文看懂大数据的技术生态圈,Hadoop,hive,spark都有了 转载: 大数据本身是个很宽泛的概念,Hadoop生态圈(或者泛生态圈)基本上都是为了处理超过单机尺度的数据处理而诞生的.你可以把它 ...

  6. SQL语句的拼凑

    StringBuilder sql = new StringBuilder("SELECT * FROM t_customer WHERE 1=1"); /* * 2. 判断条件, ...

  7. 理解position:relative

    前言:position有5个属性:static.absolute.relative.fixed和inherit.本篇博客主要介绍relative属性,因为似乎很多人对这个属性的理解很模糊,而且不清楚r ...

  8. 使用WampServer搭建本地PHP环境,绑定域名,配置伪静态

    倡萌之前介绍过 USBWebserver 快速搭建本地PHP环境 ,推荐USBWebserver的原因在于它是绿色的,不需要安装,想使用就手动运行下即可.但是 USBWebserver 也有自身的弱点 ...

  9. System.out.println与System.err.println的区别

    public class Test2 { static { System.out.println("1"); } { System.out.println("2" ...

  10. C/C++标准有哪些?

                        1. C 时间 名称 标准制定组织 事件 1978 K&R标准 K&R <The C Programming Language>   ...