ACM 线段树 + 树状数组
文章平均质量分 81
huixisheng
无所谓结果如何,只要一直坚持并努力就好!!
展开
-
http://acm.hdu.edu.cn/showproblem.php?pid=1166
<br />/* 照着别人的思路写的线段树,暴露了很多的错误,tree的范围的定义 更新 查找右边的结点的时候 mid + 1总是忘记 万事起头难!!!*/#include <iostream>#include <cstdio>#include <cstring>#include <string>using namespace std;const int N = 50005;struct Tree{ int l, r, sum;};Tree tree[原创 2010-08-10 00:50:00 · 898 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1542 矩形面积的并 线段树 + 扫描线 + 离散化
<br />#include <iostream>#include <cstdio>#include <algorithm>#define LL(x) ((x) << 1)#define RR(x) ((x) << 1 | 1)using namespace std;const int N = 100005;struct Seg_tree{ int l, r; int st; double sum; int mid(){ return (l + r) >>原创 2010-08-20 12:57:00 · 496 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1541 结点更新求最左区间的个数
<br />/* * 少写一个询问的函数,以为一个更新的函数就够了,结果。。。。 * 就是结点更新求最左区间的个数 */#include <iostream>#include <cstdio>#include <cstring>#define LL(x) ((x) << 1)#define RR(x) ((x) << 1 | 1)using namespace std;const int N = 32005;struct Seg_tree{ int l原创 2010-08-20 17:42:00 · 476 阅读 · 1 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=2227 dp + 线段树
<br />/* * 说什么好呢?对于这个题目写了好几天 感觉 dp + 线段树 总有道关卡,一直突破不了,总是在漫无边际的沼泽挣扎 * 因为这样心情严重受挫 * 区间的维护总是很难跟dp 联系在一起,单单的区间维护是会的,但是感觉牵扯上了dp,就什么都不会了,dp 。。一个字,怕 * 或许挣扎就是收获吧,渐渐地应该学会如何取分析问题,如何看待wrong * 一开始敲代码的时候。我就是完全没有理解题目,想当然的理解题目是一个悲剧阿 * * 题目求的是一个序列中非递原创 2010-08-25 17:10:00 · 871 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1779 线段树 求区间最大值 结点更新
<br /> #include <iostream>#include <cstdio>#define LL(x) ((x) << 1)#define RR(x) ((x) << 1 | 1)using namespace std;const int N = 100005;struct Seg_tree { int l, r; int val; //本区间累加值 int maxval; //记录子区间最大值 int loction; //子区间最大值位置原创 2010-08-29 21:07:00 · 708 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=2642 二维线段树
/* 二维线段树*/#include #include #include #define LL(x) ((x) > 1; }};struct Main_tree{ int lx, rx; Sub_tree sub[4 * N]; int mid(){ return (lx + rx) >> 1; }}tree[4 * N];bool hash[N][N];bool readint(int &ret){ int sgn; char原创 2010-08-29 02:07:00 · 474 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=3015 树状数组
<br />/*纯属参考 : http://hi.baidu.com/forverlin1204/blog/item/98cb564dcdcc25f5d62afc61.html 树状数组题目描述:给定一个长为n的序列,元素有两个属性x,h(x代表坐标,h代表高度)求任意点(i,j)对的不调和值之和,不调和值有两部分组成F和SF是指i和j的x坐标(离散化后)差的绝对值F=abs(x[i]-x[j])S是指i和j的高度(离散化后)S=min(h[i],h[j]),这两者之积F*S就是(i原创 2010-08-30 06:36:00 · 649 阅读 · 1 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=2688 数状数组 线段树
<br />/* 这个题目对于线段树时间卡的很紧,所以才迫不得已学习树状数组 */#include <iostream>#include <cstdio>#include <cstring>#define lowbit(x) (x & (-x)) // 具体怎么实现我也不知道using namespace std;const int N = 10005;const int M = 3000005;int tree[N];int df[M];int Quer原创 2010-08-27 18:55:00 · 520 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=3450 线段树 + dp
<br />/* 这题是凭着感觉写的 */#include <iostream>#include <cstdio>#include <algorithm>#define LL(x) ((x) << 1)#define RR(x) ((x) << 1 | 1)using namespace std;const int N = 100005;const int mod = 9901;struct Seg_tree{ int l, r, sum; int mi原创 2010-08-27 22:40:00 · 522 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1255 扫描线 + 线段树 +离散化
<br />/* * 这个跟昨天写的矩形面积的并是差不多的,而且我译开始还是写的一样的,sample都相差那么一点的 * 看了别人的加了moresum就OK那里的更新还是有点不理解的,转下一下的供自己回忆题意:求矩形的交的面积!覆盖两次或以上!将每个矩形的两条纵向边看成两个事件点,遇到左端点,插入该纵向边,遇到右节点,删除该边!对所有y坐标进行离散化!进行线段树的插入和更新操作!其实这道题跟求矩形的并的面积类似。不同的是更新每个节点覆盖长度的操作!我采用cover,once,原创 2010-08-20 15:20:00 · 1138 阅读 · 1 评论 -
http://acm.pku.edu.cn/JudgeOnline/problem?id=3667 区间更新+求满足长短的最左区间
<br />#include <iostream>#include <cstdio>#include <algorithm>#define LL(x) ((x) << 1)#define RR(x) ((x) << 1 | 1)using namespace std;const int N = 500005;struct Seg_tree { int l, r; int st; int l_size, size, r_size; int mid() { re原创 2010-08-19 19:26:00 · 554 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1166 更新节点,区间求和
<br />/* 更新节点,区间求和*/#include <iostream>#include <cstdio>#include <cstring>#include <string>using namespace std;const int N = 50005;struct Tree{ int l, r, sum;};Tree tree[3 * N];int num[N];inline void DFS_tree(int node, int l, in原创 2010-08-13 21:26:00 · 508 阅读 · 1 评论 -
http://acm.pku.edu.cn/JudgeOnline/problem?id=2528 成段更新,区间统计颜色的种类(离散化处理线段)
<br />/* * 成段更新,区间统计颜色的种类(离散化处理线段) */#include <iostream>#include <cstdio>#include <algorithm>#include <bitset>#include <cstring>#define LL(x) ((x) << 1)#define RR(x) ((x) << 1 | 1)using namespace std;const int N = 10010;struct Line原创 2010-08-16 18:36:00 · 610 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1698 成段更新,总区间求和
<br />/* 成段更新,总区间求和,刚开始学线段树,只有参考别人的代码的时候才能写出来*/#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#define LL(x) ((x) << 1)#define RR(x) ((x) << 1 | 1) // 看来以后要学会写这个啊using namespace std;const int N = 100005;struc原创 2010-08-13 21:19:00 · 540 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1754 更新节点,区间最值
<br />/* 更新节点,区间最值,这个题目可以参考模板勉强写出来*/#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 600005;struct Seg_tree{ int l, r, max; int mid(){ return (l + r) / 2; }}tree[N];i原创 2010-08-13 21:23:00 · 334 阅读 · 0 评论 -
http://acm.pku.edu.cn/JudgeOnline/problem?id=3468 成段更新,区间求和(要用long long)
<br />/* 好不容易AC的, vim这个插件有时海的我好惨的. */#include <iostream>#include <cstdio>#define LL(x) ((x) << 1)#define RR(x) ((x) << 1 | 1)using namespace std;const int N = 100005;struct Seg_tree{ int l, r; long long val; // 保存一段区间内增加的值 long原创 2010-08-16 14:06:00 · 382 阅读 · 0 评论 -
http://acm.pku.edu.cn/JudgeOnline/problem?id=2777 成段更新,区间统计颜色的种类 (用的位运算, 可是写的很搓)
/* 一开始以为跟hdu1698一样的,而这个题目求的是颜色的种类, hdu1698求的区间的和,sb的以为题目求的是一样的 线段建树是写的有点熟起来的,可是主要的Update还是不会的 */#include #include #include #define LL(x) ((x) > 1; }}tree[N * 3];bool hash[100];inline void Build(int l, int r, int node){ tree[node].l原创 2010-08-15 21:42:00 · 698 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=2871 更新最左区间
<br />/* 这题跟pku hotel 是一样的,只是询问没有那么明显 new w 可以先找到最左边长度为w的内存块,求的其最左边的下标l 然后 l 到 l + w - 1 这个区间进行更新 并且把l , l + w - 1 存入数组,方便Get Free 操作 */#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#defi原创 2010-08-19 19:21:00 · 403 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1540 更新节点,询问节点所在的位置有多少连续的区间
<br />/* * 这个题目跟hotel差不多的,可以说是一样的。好就没有用vector了,陌生了 * 更新节点,询问节点所在的位置有多少连续的区间 */#include <iostream>#include <cstdio>#include <cstring>#include <vector>#include <algorithm>#include <stack>#define LL(x) ((x) << 1)#define RR(x) ((x) << 1 |原创 2010-08-18 18:37:00 · 524 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=2795 更新节点构造线段数很关键,询问特殊
<br />/* 题意:有一个广告牌,高是h宽为w。现在要在上面贴纸条做广告,每个纸条都是单位长度的, 也就是h = 1;宽不一致!要求尽可能的往顶头贴,其次尽可能的往左边贴, 求给出规格的纸条能贴在广告牌上的第几行!(1 到 h) 然而 1 <= h , w <= 10^9 这个大的范围,如何线段树开不了那么大的数组 n <= 200000; 假设给我们n个数据都是1*w(w == 10^9),不是最多只能贴20000行么?? 这个题目跟平常作的有点不一样的,原创 2010-08-16 20:47:00 · 537 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1823 二维线段树
<br />/* 二维的线段树跟一维的似乎一样的 身高建为x轴 活泼度为y轴*/#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#define LL(x) ((x) << 1)#define RR(x) ((x) << 1 | 1)using namespace std;const int N = 100;struct Sub_tree { int l, r原创 2010-08-29 00:23:00 · 540 阅读 · 0 评论