
【kuangbin专题】 线段树
青鱼一条
小白一枚
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
hdu1166 排兵布阵(单点查询线段树模板题)
#include<iostream> using namespace std; const int maxn = 1e5; int a[maxn],b[4*maxn]; void pushUp(int i) { b[i] = b[i * 2] + b[i * 2 + 1]; } void build(int i,int l,int r) { if(l == r) ...原创 2019-04-24 11:19:02 · 172 阅读 · 0 评论 -
hdu1754 I Hate It(单点查询线段树,区间最大值)
模板题 #include<iostream> #include<algorithm> using namespace std; const int maxn = 3e5; typedef long long ll; ll Max[4 * maxn]; void pushUp(int i) { Max[i] = max(Max[i * 2],Max[i * 2 ...原创 2019-04-24 11:26:14 · 134 阅读 · 0 评论 -
poj3468 A Simple Problem with Integers(区间线段树)
线段树区间查询模板题 #include<iostream> #include<cstring> using namespace std; const int maxn = 2e5; typedef long long ll; ll add[4*maxn],b[4*maxn]; void pushUp(int i) { b[i] = b[i*2] + b[i*2...原创 2019-04-24 11:28:46 · 135 阅读 · 0 评论 -
hdu1698 Just a hook(线段树)
对于给定区间利用线段树进行维护,在Q次修改之后,进行n次查询,将每一位的值加起来即为结果。没有什么坑点。 #include<iostream> using namespace std; const int maxn = 1e5+5; int segment[4*maxn]; int n; void pushdown(int i) { if(segment[i]) ...原创 2019-04-24 17:00:05 · 103 阅读 · 0 评论 -
poj2528 Mayor's posters (离散化+线段树,区间修改,单点查询)
对整个区间进行标记,查询时进行单点查询,最后统计出现了多少种。 #include<iostream> #include<cstring> #include<set> #include<algorithm> using namespace std; const int maxn = 1e5+5; typedef long long ll; int ...原创 2019-04-24 11:41:27 · 205 阅读 · 0 评论 -
zoj1610 count the colors(线段树)
题目大意:n次操作,每次对一段区间进行染色。问最后有每种颜色有多少段。 解题思路:对区间颜色进行维护。注意,区间应该是从1到8000的(每次输入的区间是左开右闭区间,是个坑),颜色为0到8000。n次更新后,查询每个点对应的颜色,若跟前一个点颜色不同,则进行计数,最后输出即可。 #include<iostream> #include<cstring> using na...原创 2019-04-24 17:48:14 · 121 阅读 · 0 评论 -
poj3264 Balanced Lineup(线段树水题)
题目大意:给定n个值,执行q次查询,输出区间最大值和区间最小值的差。 解题思路:维护两颗线段树,一颗维护区间最大值,一颗维护区间最小值即可。 做的时候忘了开4倍数组re了一次,cin、cout超时又tle了一次,可以说很蠢了emmmmmmm #include<iostream> #include<algorithm> #include<cstdio> u...原创 2019-04-25 14:54:39 · 187 阅读 · 0 评论