【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个数中最大值是多少结果就是,好久不碰线段树了,用数组模拟 ...
随机推荐
- 十分钟上手-搭建vue开发环境(新手教程)
想写一些关于vue的文章已经很久了,因为这个框架已经火了很久,在公司里用的框架都比较老旧,但怎么也得跟上前端发展变化的潮流,这不,开始使用vue开发项目了,一遍开发一边踩坑中,今天要记录的是五分钟搭建 ...
- windows下配置mycat与常见问题解决
mycat官网:http://www.mycat.org.cn/ wiki:https://github.com/MyCATApache/Mycat-Server/wiki MyCat使用Mysql的 ...
- [D3] Debug D3 v4 with Dev Tools
Since D3 outputs standard markup, you can use familiar dev tools and inspectors to debug your visual ...
- (转)c运行库、c标准库、windows API的区别和联系
C运行时库函数C运行时库函数是指C语言本身支持的一些基本函数,通常是汇编直接实现的. API函数API函数是操作系统为方便用户设计应用程序而提供的实现特定功能的函数,API函数也是C语言的函数实现的 ...
- trunc与round
TRUNC(number[,num_digits]) number 需要截尾取整的数字. num_digits 用于指定取整精度的数字.Num_digits 的默认值为 0. 作用:截断数字和时间 ...
- VMware Ubuntu安装具体过程
不是每个程序猿都必须玩过linux,仅仅是博主认为如今的非常多server都是linux系统的,而自己属于那种前端也搞.后台也搞,对框架搭建也感兴趣,可是非常多生产上的框架和工具都是安装在server ...
- OC学习篇之---文件的操作
今天我们来介绍OC中文件操作,在之前的文章中,已经接触到了文件的创建了,但是那不是很具体和详细,这篇文章我们就来仔细看一下OC中是如何操作文件的: 第一.首先来看一下本身NSString类给我们提供了 ...
- 【BZOJ 3172】单词
[链接]h在这里写链接 [题意] 给你n个单词; 这n个单词组成了一篇文章; 问你每个单词在这篇文章中出现了多少次. 其中每个单词之间用一个逗号隔开->组成一篇文 ...
- Linux动态链接库的创建与使用
Linux动态链接库的创建与使用1. 介绍 使用GNU的工具我们如何在Linux下创建自己的程序函数库?一个“程序函数库”简单的说就是一个文件包含了一些编译好的代码和数据,这些编译好的代码和数 ...
- HDU 1287 破译密码 异或运算
http://acm.hdu.edu.cn/showproblem.php?pid=1287 题目: 有个叫"猪头帮"的国家,采用一种简单的文法加密,他们所用的语言里面只有大写字母 ...