【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个数中最大值是多少结果就是,好久不碰线段树了,用数组模拟 ...
随机推荐
- COGS——C 908. 校园网 || 洛谷——P 2746 [USACO5.3]校园网Network of Schools
http://www.cogs.pro/cogs/problem/problem.php?pid=908 || https://www.luogu.org/problem/show?pid=27 ...
- iOS开发RunLoop学习:一:RunLoop简单介绍
一:RunLoop的简单介绍 #import "ViewController.h" @interface ViewController () @end @implementatio ...
- Android小经验
转载自:http://mp.weixin.qq.com/s?__biz=MzA4MjU5NTY0NA==&mid=404388098&idx=1&sn=8bbbba7692dc ...
- POJ 2402 Palindrome Numbers(LA 2889) 回文数
POJ:http://poj.org/problem?id=2402 LA:https://icpcarchive.ecs.baylor.edu/index.php?option=com_online ...
- MongoDB 管理
1.给数据库增加分片功能 mongos> use admin mongos> db.runCommand({enablesharding:"cipnet"}) mong ...
- 通过双重for循环来找到JSON中不反复的数据
//通过双重for循环来找到JSON中不反复的数据 var count = 0; for ( i=0; i<json.length; i++) { for ( j=0; j<i; j++) ...
- h5 video 点击自动全屏
加上如下属性 https://blog.csdn.net/weixin_40974504/article/details/79639478 可阻止自动全屏播放,感谢 https://blog.csdn ...
- x265探索与研究(四):怎样编码视频?
怎样编码视频? 本文介绍x265中的两种编码视频方法,一是採用命令行的方法.二是GUI的方式. 1.命令行的方法 (1).第一种方式生成*.265格式的视频文件 ...
- event.relatedTarget、event.fromElement、event.toElement
在标准DOM中,mouseover和mouseout所发生的元素可以通过event.target来访问,相关元素通过event.relatedTarget属性来访问.event.relatedTarg ...
- [Django] Auth django app with rest api
First, start the env: . bin/activate Then cd to our module cd djangular Create a new app: python man ...