线段树
傻笨
这个作者很懒,什么都没留下…
展开
-
杭电1698
这题我看着学长的代码敲了四遍,终于对了!我都背出来了!苦逼啊! #include #include using namespace std; const int maxn=100005; #define lz 2*u,l,mid #define rz 2*u+1,mid+1,r int sum[4*maxn]; int flag[4*maxn]; void build原创 2013-05-18 20:00:09 · 642 阅读 · 0 评论 -
杭电1166
#include #include using namespace std; const int maxn=50005; int sum[4*maxn]; int a[maxn]; void build(int u,int l,int r) { if(l==r) { sum[u]=a[l]; return ;原创 2013-05-18 17:06:19 · 548 阅读 · 0 评论 -
HDU 4217
这道题目有人用动态规划做的,而我最近在写线段树,就借鉴大牛的线段树代码! 题目大意如下: 题意:给你一个N,K;然后又有K个数i;表示从1,2,3…N个数 经过K次操作,每次操作是去掉第i小的数。求所有去掉数的之和; 代码如下: #include #include using namespace std; const int maxn=262150; int a[maxn*原创 2013-05-24 21:33:22 · 482 阅读 · 0 评论 -
HDU 1754
这道线段树的题目, #include #include #include const int maxn=200005; using namespace std; int a[4*maxn]; void build(int u,int l,int r) { if(l==r) { scanf("%d",&a[u]);原创 2013-05-21 18:32:28 · 562 阅读 · 0 评论 -
poj3264
#include #include #include #include using namespace std; const int maxn=50005; int root[4*maxn]; int root1[4*maxn]; int a[maxn]; int max1,min1; const int inf=1000005; void build(int u,int l,int r)原创 2013-07-11 09:00:37 · 634 阅读 · 0 评论 -
HDU 3074
这道题目我用一般线段树写,发现超时了,后来用结构体,就过了,于是才知道结构体速度会快好多!代码如下: #include #include #include const int maxn=50005; const int D=1000000007; __int64 a[maxn]; using namespace std; struct node { int l,r; long原创 2013-07-12 19:31:21 · 506 阅读 · 0 评论 -
hdu 2795
/* 这道题目如果你想通了,知道可以用线段树的话,那么这是一道简单的线段树题目,我比赛的时候没有想出来, 赛后做时,看了别人的代码,才明白过来,就是以广告牌的长度建树,当为叶子节点时,它的值为广告牌的宽度, 后然不断的询问,如果真正理解了线段树的意义的话,就可以马上知道该题是用线段树,我只是菜鸟,不过这道题目 还有几个细节要注意一下,不然也过不了,下面我会注释出来! */ #include #原创 2013-07-19 10:10:49 · 438 阅读 · 0 评论 -
POJ 2528 Mayor's posters 线段树+离散化
树基础知识 从简单说起,线段树其实可以理解成一种特殊的二叉树。但是这种二叉树较为平衡,和静态二叉树一样,都是提前已经建立好的树形结构。针对性强,所以效率要高。这里又想到了一句题外话:动态和静态的差别。动态结构较为灵活,但是速度较慢;静态结构节省内存,速度较快。 接着回到线段树上来,线段树是建立在线段的基础上,每个结点都代表了一条线段[a , b]。长度为1的线段成为元线段。非元线段都有两个子结点,转载 2013-07-19 10:20:43 · 439 阅读 · 0 评论 -
线段树
一般能用树状数组解决的问题,都可以用线段树解决。但是能用线段树解决的问题,树状数组不一定能解决。可能有人会有疑问,那你为什么还要写树状数组啊,因为树状数组实现起来比线段树简单百倍,非常容易掌握。 关于线段树,分享几个别人写的文章。我就不粘贴了,嘿嘿 http://blog.csdn.net/tsaid/article/details/6665764 线段树基础知识。 http://www.ah转载 2013-07-19 10:23:11 · 546 阅读 · 0 评论