【BZOJ 1012】 [JSOI2008]最大数maxnumber(线段树做法)
【题目链接】:http://www.lydsy.com/JudgeOnline/problem.php?id=1012
【题意】
【题解】
预开一个20W长度的线段树;
这里a[1..20W]={0};
每次对单个点进行修改操作;
然后返回区间的最大值;
【完整代码】
/**************************************************************
Problem: 1012
User: chengchunyang
Language: C++
Result: Accepted
Time:1032 ms
Memory:9104 kb
****************************************************************/
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 2e5+100;
LL a[N], ma[N << 2],d,lastans = 0,ne_w;
int m,len = 0;
void up_data(int pos, int l, int r, int rt)
{
if (l == r)
{
ma[rt] = ne_w;
return;
}
int m = (l + r) >> 1;
if (pos <= m)
up_data(pos, lson);
else
up_data(pos, rson);
ma[rt] = max(ma[rt << 1], ma[rt << 1 | 1]);
}
LL query(int L, int R, int l, int r, int rt)
{
if (L <= l && r <= R)
return ma[rt];
int m = (l + r) >> 1;
LL temp1 = -1, temp2 = -1;
if (L <= m)
temp1 = query(L, R, lson);
if (m < R)
temp2 = query(L, R, rson);
return max(temp1, temp2);
}
int main()
{
//freopen("F:\\rush.txt", "r", stdin);
rei(m), rel(d);
rep1(i, 1, m)
{
char key; LL t;
key = getchar();
scanf("%c %lld", &key, &t);
if (key == 'A')
{
ne_w = (t + lastans) % d;
len++;
up_data(len, 1, 200000, 1);
}
else
lastans = query(len - t + 1, len, 1, 200000, 1), printf("%lld\n", lastans);
}
return 0;
}
【BZOJ 1012】 [JSOI2008]最大数maxnumber(线段树做法)的更多相关文章
- 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 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作.语法:Q L 功能: ...
- 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 MBSubmit: 10374 Solved: 4535[Subm ...
- BZOJ 1012: [JSOI2008]最大数maxnumber 单调队列/线段树/树状数组/乱搞
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 4750 Solved: 2145[Submi ...
- 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 [JSOI2008]最大数maxnumber【线段树】
水题,每次记录一下当前有多少个数,然后按照题目所指示的那样模拟就行,每次向线段树末尾插入(其实是修改)题目中指定的数,然后询问当前的个数到前面Q个数中最大值是多少结果就是,好久不碰线段树了,用数组模拟 ...
随机推荐
- 洛谷 P2807 三角形计数
P2807 三角形计数 题目背景 三角形计数(triangle) 递推 题目描述 把大三角形的每条边n等分,将对应的等分点连接起来(连接线分别平行于三条边),这样一共会有多少三角形呢?编程来解决这个问 ...
- JQ实现选项卡(jQuery原型插件扩展)
下边分为两个版本,一种是点击切换选项(index.js),一种是滑过切换选项(index1.js) HTML文件: jq使用jquery-1.11.3.js版本 <!DOCTYPE html&g ...
- 【Codeforces Round #301 (Div. 2) E】Infinite Inversions
[链接] 我是链接,点我呀:) [题意] 给你一个无限长的序列1,2,3,4... 然后给你n个操作. 每个操作ai,bi; 表示调换位置为ai和位置为bi的数的位置. (ai,bi<=10^9 ...
- uva 10710 - Chinese Shuffle(完美洗牌)
option=com_onlinejudge&Itemid=8&category=474&page=show_problem&problem=1651"> ...
- POJ 3278 Catch That Cow(BFS 剪枝)
题目链接:http://poj.org/problem?id=3278 这几次都是每天的第一道题都挺顺利,然后第二道题一卡一天. = =,今天的这道题7点40就出来了,不知道第二道题在下午7点能不能出 ...
- netty reactor线程模型分析
netty4线程模型 ServerBootstrap http示例 // Configure the server. EventLoopGroup bossGroup = new EpollEvent ...
- orabbix自定义监控oracle
前提:安装orabbix 好后能正常运行, 检验条件(1). 最新数据有数据 (2).图形有显示 (3).日志不报错 /opt/orabbix/logs/orabbix.log 添加方法: 1. ...
- 【习题 3-2 UVA - 1586】Molar mass
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟. 主要是找那个数字. [代码] #include <bits/stdc++.h> using namespace ...
- 解决linux下cocos2dx不能播放声音
cocos2dx2.2.1在linux下引用#include "SimpleAudioEngine.h".报错找不到该文件. 改动makefile文件,加入 SHAREDLIBS ...
- 【Codeforces Round #439 (Div. 2) B】The Eternal Immortality
[链接] 链接 [题意] 求b!/a!的最后一位数字 [题解] b-a>=20的话 a+1..b之间肯定有因子2和因子5 答案一定是0 否则暴力就好 [错的次数] 在这里输入错的次数 [反思] ...