线段树
文章平均质量分 76
自爄創煇熿
这个作者很懒,什么都没留下…
展开
-
线段树 成段更新
线段树就是许多线段组成的,并对每条线段进行操作,线段树的节点满足二叉树,所以某个节点的左右儿子是 2*rt,和2*rt+1; 举例说明:已知线段[2,5] [4,6] [0,7];求点2,4,7分别出现了多少次 在[0,7]区间上建立一棵满二叉树:(为了和已知线段区别,用【】表示线段树中的线段)原创 2012-10-22 21:19:32 · 455 阅读 · 0 评论 -
CodeForces - 292E 线段树
题意:给a,b两个数组, 然后有m个操作,t 如果t=2 ,接着输入一个k ,然后输出b【k】;如果t =1,接着输入3个数,x,y,k,表示b【y】到b【y+k-1】等于 a【x】到a【x+k-1】。 线段树设置两个变量,flag1 表示这段区间被x占用,flag2表示这段区间从y位置开始, #include #include #include using namespace std; #原创 2013-08-11 18:32:18 · 632 阅读 · 0 评论 -
poj 3321 线段树(将点转换为对应区间)
题意:n个点,n-1条边,有m个查询,Q a,表示a的子树中包含a有多少苹果。C a,表示a这个点如果有苹果就被摘掉,没有苹果就长出一个。 将对应点转换成对应区间,然后进行线段树 #include #include #include using namespace std; #define mem(x,y) memset(x,y,sizeof(x)) const int N=1e5+2; st原创 2013-08-10 10:45:52 · 676 阅读 · 0 评论 -
hdu 4614 线段树
题意:有n个花瓶,编号为0 到 n-1,有m的操作,每个操作输入k,a,b,k=1,表示从标号为a的花瓶开始连续插花,每个瓶插一朵。如果某个瓶被占用,就在这瓶后面的瓶插花,到编号为n-1的瓶还有花,就扔掉剩下的花,并输出 这部操作插花的第一个瓶编号和最后一个瓶标号, k=2 表示在区间a b之间,把插的花扔掉,并输出扔掉花的数目, #include #include #include us原创 2013-07-27 10:28:59 · 522 阅读 · 0 评论 -
hdu4512
题意为求给定序列中单调递增子序列,且相邻的两个小标之差大于d; 用线段树可解,(单点更新,查询线段) 线段树中的点是存以a【i】结尾的所要求的字串的最大值,动态规划也可解,但自己不明白如何变形,路过大神留下意见; 线段树代码: #include #include #include const int maxn=100110; int tree[4*maxn]; int maxnum(i原创 2013-03-25 21:08:37 · 888 阅读 · 0 评论 -
hdu4046类似于单点更新
题意即为求wbw在所给范围的字符串中出现的次数。 线段树求解; 线段树中每个节点存的是以该节点结尾的三个字符,如果是wbw,该节点就为1,否则为0,需要注意的是更新的时候,如果该节点不是wbw,原本为1的应该改为0; 代码如下: #include #include #define maxn 50002 struct tt { int l,r; int sum; }; tt原创 2012-11-11 08:43:47 · 530 阅读 · 0 评论 -
线段树求区间最大值与最小值的差
http://poj.org/problem?id=3264 #include #include #include #include using namespace std; #define L(x) (x << 1) #define R(x) (x << 1 | 1) #define INT_MAX 0x7fffffff const int MAX = 50010; struct Tnode原创 2012-10-27 10:34:20 · 2121 阅读 · 0 评论 -
线段树Hotel
#include #include #define maxn 50002 int sum[4*maxn],lsum[maxn*4],rsum[maxn*4]; int col[maxn*4]; void buildtree(int l,int r,int rt) { col[rt]=-1; lsum[rt]=rsum[rt]=sum[rt]=r-l+1; if(l==r)原创 2012-11-03 15:00:58 · 332 阅读 · 0 评论 -
线段树+离散化Mayor's posters
线段树很简单,主要是离散化。 #include #include #include #define N 40005 int flag[N],ans; struct tree { int l,r,c; }T[N*3]; struct node { int x,y; }p[N]; struct line { int s,num; }L[N*3]; void build(i原创 2012-11-02 17:20:09 · 643 阅读 · 0 评论 -
线段树 C. Circular RMQ
http://acm.uestc.edu.cn/problem.php?pid=1393 线段树,RMQ。 #include #include #define maxn 800080 #define MAX 0x7fffffff __int64 sum[maxn]; __int64 col[maxn]; __int64 MIN(__int64 a, __int64 b) {原创 2012-11-02 14:51:52 · 695 阅读 · 0 评论 -
poj 2886 线段树 (用反素数)
题意:有n 个人,每个人有一个卡,上面有一个非零的数。第一次给一个数k,第k个人跳出,然后看第k的卡上数字是多少,如果大于0 则顺时针数那人人跳出。小于零,逆时针数到的那个人跳出,一次类推,第x次跳出的人会得到f(x),f(x)等于x的因子个数,求最大的f(x) f(x)满足反素数。 线段树的区间存的是有多少人。 #include #include #include using namespa原创 2013-08-11 14:15:43 · 597 阅读 · 0 评论