![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构 -------- 线段树
SolarDomo
每天都被头像萌醒
展开
-
线段树 学习资料
http://blog.sina.com.cn/s/blog_a2dce6b30101l8bi.html习题:http://blog.csdn.net/shiqi_614/article/details/8228102 http://blog.csdn.net/metalseed/article/details/8039326成段更新 :HDU 1698 Just a Hook: http:/原创 2016-08-10 14:54:52 · 299 阅读 · 0 评论 -
HDU 1394 Minimum Inversion Number 线段树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394代码:#include <bits/stdc++.h>#define sf scanf#define pf printfusing namespace std;/** 线段树模板 *//** 以求区间和为例 */#define lson rt << 1 , l ,mid#define原创 2016-10-08 10:51:29 · 250 阅读 · 0 评论 -
HDU 5692 Snacks DFS序 + 线段树区间更新
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5692 题意:问一个子树中,到树的根节点路径上节点最大和是多少这样可以用DFS序来维护这个树结构, 将一棵子树映射到一段区间类,区间每个树存的是相应节点到根的路径节点和,那么显然可以用一个线段树来维护这个区间的最大值。 在更新节点值的时候,我们只需要将这个节点为根的子树映射到的区间更新即可 代码:#原创 2016-10-10 14:22:14 · 295 阅读 · 0 评论 -
CodeForces 570C Replacement 线段树
题目链接:http://codeforces.com/problemset/problem/570/C单点更新区间的状态,并记录下每一个子区间左边,右边有多少个’.’,合并的时候要注意一下就可以了代码:#include <bits/stdc++.h>#define sf scanf#define pf printfusing namespace std;const int maxn = 300原创 2016-11-04 15:03:49 · 318 阅读 · 0 评论 -
线段树 区间更新模板
测试题目:HDU 1166,/** 线段树模板 *//** 以求区间和为例 */#define lson rt << 1 , l ,mid#define rson rt << 1 | 1,mid + 1,rconst int maxn = 50000 + 50;int v[maxn << 2],laze[maxn << 2];int A[maxn];// 向下Push laze标记vo原创 2016-10-08 10:16:22 · 254 阅读 · 0 评论 -
SPOJ QTREE 树链剖分 边上剖分
题目链接:http://bak2.vjudge.net/problem/13013/origin#include <cstdio>#include <cstring>#include <algorithm>#define sf scanf#define pf printfusing namespace std;/** Edge */const int maxn = 10000 + 50;原创 2016-09-21 10:33:36 · 380 阅读 · 0 评论 -
HDU 5893 List wants to travel 树链剖分 边权剖分
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5893题意:给出2种操作 1.修改u到v的路径上的边的颜色为c 2.查询u到v的路径上有多少段颜色将无根树边为有根树之后,对树进行树链剖分,得到每个点的编号 用边上深度大的节点表示边,这样就是一个树上点剖分 这样就和HYSBZ 2243一样了代码:#include <bits/stdc++.h>原创 2016-09-19 19:49:53 · 521 阅读 · 0 评论 -
HYSBZ 1036 树的统计Count 树链剖分 点权剖分
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=10361.更改点权值 2.求路径上权值和 3.求路径上最大权值 代码:#include <bits/stdc++.h>#define sf scanf#define pf printfusing namespace std;const int maxn = 30000 + 50原创 2016-09-19 14:18:19 · 228 阅读 · 0 评论 -
HYSBZ 2243 染色 树链剖分 点上剖分
题目链接:http://bak2.vjudge.net/problem/38096/origin 题意: 两种操作: 1.修改u到v路径上的点的颜色为c 2.询问u到v路径上有多少段颜色线段树上用区间合并来维护答案 主要是在询问时要考虑一下,维护上个段的最后节点颜色来维护颜色段数#include <bits/stdc++.h>#define sf scanf#define pf pri原创 2016-09-19 19:15:52 · 411 阅读 · 0 评论 -
51NOD 1672 区间交 线段树
题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1672#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>#define sf scanf#define pf printf#define L (rt <原创 2016-09-06 21:17:34 · 467 阅读 · 0 评论 -
POJ 3468 A Simple Problem with Integers 线段树 区间更新
POJ 3468 A Simple Problem with Integers: http://poj.org/problem?id=3468 区间更新 和 区间求和代码:#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>#define sf scanf#define pf printf原创 2016-08-12 21:58:22 · 310 阅读 · 0 评论 -
HDU 1698 Just a Hook 线段树区间更新
HDU 1698 Just a Hook:http://acm.hdu.edu.cn/showproblem.php?pid=1698 √ 题意:问一个数组中改变一段区间的数的大小 最后求争端区间的和 模板题代码:#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>#define sf s原创 2016-08-12 21:57:10 · 398 阅读 · 0 评论 -
POJ 2777 Count Color 线段树 区间更新
题目链接: http://poj.org/problem?id=2777代码:#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>#define sf scanf#define pf printfusing namespace std;typedef long long LL;const原创 2016-08-22 11:15:50 · 292 阅读 · 0 评论 -
POJ 1195 Mobile phones 二维线段树
题目连接:http://poj.org/problem?id=1195 二维线段树 单点更新 区间查询 代码:#include <cstdio>#include <cstring>using namespace std;const int maxn = 1000 + 50;int sum[4 * maxn][4 * maxn];#define lson rt << 1,l,mid#d原创 2016-12-04 16:22:05 · 385 阅读 · 0 评论