bzoj 1012 [JSOI2008]最大数maxnumber
原题链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1012
线段树,单点更新。。
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstdio>
#define lc root<<1
#define rc root<<1|1
using std::max;
const int Max_N = ;
const int INF = 0x3f3f3f3f;
int MOD;
struct Node { int val; };
struct SegTree {
Node seg[Max_N << ];
inline void push_up(int root) {
seg[root].val = max(seg[lc].val, seg[rc].val);
}
inline void update(int root, int l, int r, int pos, int t) {
if (pos > r || pos < l) return;
if (pos <= l && pos >= r) {
seg[root].val += t;
return;
}
int mid = (l + r) >> ;
update(lc, l, mid, pos, t);
update(rc, mid + , r, pos, t);
push_up(root);
}
inline int query(int root, int l, int r, int x, int y) {
if (x > r || y < l) return -INF;
if (x <= l && y >= r) return seg[root].val;
int mid = (l + r) >> ;
int v1 = query(lc, l, mid, x, y);
int v2 = query(rc, mid + , r, x, y);
return max(v1, v2);
}
}seg;
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
char ch;
int n, v, res, len = ;
while (~scanf("%d %d", &n, &MOD)) {
res = ;
for (int i = ; i < n; i++) {
getchar();
scanf("%c %d", &ch, &v);
if (ch == 'A') ++len, seg.update(, , n, len, (res + v) % MOD);
else printf("%d\n", res = seg.query(, , n, len - v + , n));
}
}
return ;
}
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 现在请求你维护一个数列,要求提供以下两种操作: 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 现在请求你维护一个数列,要 ...
随机推荐
- 【LeetCode】12. Integer to Roman 整型数转罗马数
题目: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from ...
- java springMVC生成二维码
Zxing是Google提供的工具,提供了二维码的生成与解析的方法,现在使用Java利用Zxing生成二维码 1),二维码的生成 将Zxing-core.jar 包加入到classpath下. 我的下 ...
- ERS-2卫星
ERS-2卫星是欧洲空间局的第二颗资源遥感卫星,携带有雷达测高仪.综合孔径雷达等多种科学仪器,是一颗多任务.多学科的科学考察卫星.[1] ERS-1 ERS-2 欧空局分别于1991年和1995年发射 ...
- Apache虚拟主机配置(多个域名访问多个目录)
Apache虚拟主机配置(多个域名访问多个目录) 为了方便管理虚拟主机,我决定使用一种方法,那就是修改httpd-vhosts.conf文件. 第一步首先要使扩展文件httpd-vhosts.conf ...
- 三、第一个Struts2应用案例(编码步骤)
第一个Struts2应用案例(编码步骤) 编写2个jsp hello.jsp <body> <a href="${pageContext.request.conte ...
- javaSE第十二天
第十二天 64 1. Scanner的使用(了解) 64 (1)在JDK5以后出现的用于键盘录入数据的类. 64 (2)构造方法: 64 (4)要掌握的两个方法 65 ( ...
- 使用C#三维图形控件进行曲线曲面分析
使用AnyCAD.Net三维图图形控件能够计算曲线的切线.法线.曲率.长度等,能够计算曲面的uv切线.法线.面积等. 代码示例一:曲线分析 Platform.LineStyle lineStyle = ...
- 必须会的SQL语句(六)查询
1.基础的查询 1)重命名列 select name as '姓名' from 表名 2)定义常量列 select 是否 ='是' from 表名 3) ...
- css3选择器 以及当天知道的东西
10.25日伪类:a:link{}未访问的链接 a:visited{}已访问的链接 a:hover{}鼠标移动到链接上 a:active{}选定的链接 注:a:hover ...
- sql批量修改插入数据
1.批量修改 select 'update 读者库 set 单位代码='''+新单位代码+''' where 单位代码='''+单位代码+'''' from 读者单位 ,)<'L' and is ...