题目链接:

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. javascript图形动画设计--以简单正弦波轨迹移动

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  2. [转]Sql Server 分页存储过程

    本文转自: 版权声明:作者:jiankunking 出处:http://blog.csdn.net/jiankunking  本文版权归作者和CSDN共有,欢迎转载,但未经作者同意必须保留此段声明,且 ...

  3. Layui 好用的弹出框

    layui的下载地址: http://www.layui.com/ 需要引用layui里面的css跟js layui自带jquery var $ = layui.$ 一个直接弹出另一个窗体的弹出框 w ...

  4. hdu 3999 二叉查找树

    The order of a Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  5. 0 test classes found in package in XXXX

    除了参考其他的方法,要注意XXXX位置下是否有空文件夹,删掉.

  6. POJ P3667 Hotel——solution

    Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and e ...

  7. JavaWeb学习总结(四):Servlet开发(二)

    一.ServletConfig讲解 1.1.配置Servlet初始化参数 在Servlet的配置文件web.xml中,可以使用一个或多个<init-param>标签为servlet配置一些 ...

  8. 前端面试经典题目(HTML+CSS)二

    1.浏览器页面由哪三层构成,分别是什么,作用是什么? 构成:结构层.表示层.行为层 分别是:HTML.CSS.JavaScript 作用:HTML实现页面结构,CSS完成页面的表现与风格,JavaSc ...

  9. 很赞的一个教程: React.js 小书

    很赞,  React.js 小书        http://huziketang.com/books/react/ 推荐阅读入门, 照着来一遍,能会个七七八八, 更多的还需要多写 import Re ...

  10. Linux 新手入门常用命令

    1,增加用户:useradd mylinux passwd mylinux 添加你的用户密码 2,切换用户: su otheruser   (注意这种切换方式只是临时的,本质工作目录还在原来的用户目录 ...