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 现在请求你维护一个数列,要 ...
随机推荐
- MSP430推荐网站
http://www.amobbs.com/thread-5092914-1-1.html http://www.amobbs.com/thread-4701106-1-1.html
- docker学习(一)
atomic使用有点费劲,我改为centos7来做为学习环境. 1 安装 epel源就自带,目前版本是1.10.3 yum -y install docker docker version Clien ...
- C# 中DataGridView 绑定List<T>做数据源的操作问题
若想将 List<T>作为DataGridView的数据源,然后后续还想继续操作的话,需要将List<T>赋值给BindingList对象, 然后直接将BindingList赋 ...
- CSS3 Filter
Filters主要是运用在图片上,以实现一些特效.(尽管他们也能运用于video上),不过我们在些只来讨论图片上的运用. 语法: elm { filter: none | <filter-fun ...
- AJAX验证用户是否存在
<html> <head> <title> ajax验证 </title> </head> <body> <input t ...
- leetcode2:Add Two Numbers
Add Two Numbers Total Accepted: 55216 Total Submissions: 249950My Submissions You are given two link ...
- VBA删除表格最后一行
Sub 删除最后一行() If MsgBox("要为所有表格添加列吗?", vbYesNo + vbQuestion) = vbYes Then To ActiveDocument ...
- 在Array原型链上扩展remove,contain等方法所遇到的坑
相信jser兄弟们肯定会碰到这样一个问题, 在做数组类的操作的时候,会要求删除数组中的一个元素:亦或是判断某值是否存在于这个数组: OK,拿删除数组元素举例,扩展方法为: Array.prototyp ...
- source insight用于C语言编程的工具脚本
简单来说,source insight提供的功能功能还不够傻瓜,用起来还不够方便,所以写了此脚本,提高开发效率. 部分source insight提供的功能也包含了进来,主要是因为我不喜欢使用太多的快 ...
- MongoDB简述
简介 MongoDB is an open-source document database that provides high performance, high availability, an ...