文章分类 -  acm数据结构-线段树

1

hdu4819 二维线段树:点修改区间查询
摘要:这是一道裸的二维线段树区间查询最大最小值+点修改,学习啦!二维线段树其实就是在一维线段树的每一个节点上增加一个一维线段树具体从x节点传到y节点还要看是区间还是节点,大部分操作都和一维线段树差不多 1 #include 2 #include 3 #include 4 using namespa... 阅读全文

posted @ 2015-02-09 01:04 xiao_xin 阅读(269) 评论(0) 推荐(0)

hdu3954 线段树 打怪升级,等级不同加经验不同,询问区间经验值最高
摘要:或许,是我理解错了。完全可以把大白书上的maintain当成pushup。其实只要完全理解了,什么姿势都能把线段树打出来。话题回到这道题目,开一个maxv二维数组,记录等级为i的人在该区间最大经验,然后用线段树(levelup)进行升级。 1 #include 2 #include 3 #inclu... 阅读全文

posted @ 2015-01-08 01:12 xiao_xin 阅读(131) 评论(0) 推荐(0)

hdu4027 线段树(区间开平方,区间求和)
摘要:本题的线段树区间更新不能用区间更新做,因为不满足:区间和的更新==区间内每个数更新的和所以实际上是单点更新,单点更新不是退化成On2了吗?不,因为要知道一点64位整数开平方七八次就变成1了,退化成1的区间我们不去更新他,正确计算复杂度为O(10*m*log(n));类似开方这些变化很快的,think... 阅读全文

posted @ 2015-01-04 16:05 xiao_xin 阅读(179) 评论(0) 推荐(1)

hdu4747 线段树区间修改值,区间查询和及最大值即最大值位置
摘要:很久以前就看到过这个题目,当时刚学线段树看了题解还是感觉敲不出来。现在重新做这道题目感觉思路很难想到,代码量也不小,加深了对lrj大白书中pushdown和maintain的理解。预处理从1开始到i的值。然后一个一个更改,求和。具体细节,包括如何找到更改的左端点和右端点,这些需要仔细思考。think... 阅读全文

posted @ 2015-01-03 14:41 xiao_xin 阅读(431) 评论(0) 推荐(0)

hdu4614 线段树区间修改值,区间查询和
摘要:第一个二分查找的是第num个0,第二个二分查找的是最后一个0把lrj大白书里的线段树重打一遍成以后模板,关于里面的maintain函数: 1 #include 2 #include 3 #include 4 using namespace std; 5 int n,ll; 6 int setv[20... 阅读全文

posted @ 2015-01-02 23:42 xiao_xin 阅读(123) 评论(0) 推荐(0)

hdu3577 区间加值,区间查询最大值
摘要:裸==1.从x更新到y-12.注意格式 1 #include 2 #include 3 #include 4 using namespace std; 5 #define n 1000000 6 int ans[100005],maxv[4000005],addv[4000005]; 7 void ... 阅读全文

posted @ 2015-01-02 17:48 xiao_xin 阅读(131) 评论(0) 推荐(0)

hdu4366 线段树:dfs序将树型转化为线型
摘要:求一个点的下属中能力比自己高,且在所有下属中忠诚度最高的点。dfs扫出左端点右端点,然后按照能力从大到小,id从小到大排序。然后简单的线段树单点修改(忠诚值),区间查询最大(忠诚值)。 1 #include 2 #include 3 #include 4 #include 5 using names... 阅读全文

posted @ 2015-01-01 13:02 xiao_xin 阅读(116) 评论(0) 推荐(0)

hdu2836(2009多校第三场) 相邻项绝对值小于等于k的序列数(线段树+sort unique lowerbound)
摘要:和codeforces上次那个题目差不多吧,都是用线段树求和加速dp为了下次好找,把几个stl放标题哈哈哈 1 #include 2 #include 3 #include 4 using namespace std; 5 #define MOD 9901 6 int sumv[400005],a[... 阅读全文

posted @ 2014-12-12 17:03 xiao_xin 阅读(127) 评论(0) 推荐(0)

hdu5091(上海邀请赛B) 线段树+扫描线:求固定大小矩形内最多点个数
摘要:过几天再看看别人怎么做的。。我是根据以前做的一道题目想到的思路,将某点变为2条线,该点是第一条线下面,线值为1,另一点在右边那条线下面,值为-1然后区间修改求最大值。。 1 #include 2 #include 3 #include 4 using namespace std; 5 int tmp... 阅读全文

posted @ 2014-11-02 17:30 xiao_xin 阅读(288) 评论(0) 推荐(1)

CodeForces 474F 线段树水题:求区间gcd和区间最小值,最小值个数
摘要:1 #include 2 #include 3 int a[1000005],minv[1000005],num[1000005],gcdv[1000005]; 4 int gcd(int x,int y) 5 { 6 if (y==0) return x; 7 return gc... 阅读全文

posted @ 2014-10-07 18:44 xiao_xin 阅读(304) 评论(0) 推荐(0)

CodeForces 474E 满足变化范围条件的最长上升序列:线段树加速
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 long long a[1000005],b[1000005],pre[100005],maxv[1000005],from[100000... 阅读全文

posted @ 2014-10-07 18:42 xiao_xin 阅读(186) 评论(0) 推荐(0)

hdu5036 线段树(dfs序使树形结构转化为线性结构)(map,pair)
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 mapmp; 8 pairegd[120005]; 9 int y1,y2,time_,now; 10 int next... 阅读全文

posted @ 2014-09-25 20:58 xiao_xin 阅读(231) 评论(0) 推荐(0)

hdu1156两颗线段树 点修改求和(数组存放扫描线)
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 struct dian 6 { 7 int x,y; 8 }s[200005]; 9 int leftnum[500005],rightnum[500005... 阅读全文

posted @ 2014-07-28 03:04 xiao_xin 阅读(138) 评论(0) 推荐(0)

hdu1542 二维如何转化为线段树
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 struct LINE 6 { 7 double x,ydown,yup; 8 int flag; 9 bool operator=1)32 ... 阅读全文

posted @ 2014-07-27 01:48 xiao_xin 阅读(98) 评论(0) 推荐(0)

hdu3333 线段树点修改区间求和(离散化判重)+离线算法
摘要:1 #include 2 #include 3 int ql,qr,p; 4 long long fsum,v; 5 int f[100005],g[100005],a[100005],b[100005]; 6 int r[100005],l[100005],hash[100005],... 阅读全文

posted @ 2014-07-25 03:12 xiao_xin 阅读(188) 评论(0) 推荐(1)

hdu1394 线段树点修改区间求和
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 int p,v,ql,qr,fsum,sumv[10005],d[10005],a[10005]; 7 void update(int o,int l,int ... 阅读全文

posted @ 2014-07-24 19:47 xiao_xin 阅读(132) 评论(0) 推荐(0)

hdu1540 线段树点修改(较难)
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 int ql,qr,x,n,ll[150005],rl[150005],a[150005]; 7 stacks; 8 void build(in... 阅读全文

posted @ 2014-07-24 01:32 xiao_xin 阅读(139) 评论(0) 推荐(0)

hdu1698 线段树区间赋值
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 int yy2,yy1,v,fsum; 8 int sumv[1000005],setv[1000005]; 9 10 void main... 阅读全文

posted @ 2014-07-23 12:36 xiao_xin 阅读(157) 评论(0) 推荐(0)

poj2528 线段树区间修改(加值)
摘要:1 #include 2 #include 3 int addv[100005],minv[100005],fmin,y1,y2,v,l[20005],d[20005],len[20005]; 4 int min(int x,int y) 5 { 6 if (x=r) addv[o]+=v... 阅读全文

posted @ 2014-07-22 23:39 xiao_xin 阅读(119) 评论(0) 推荐(0)

hdu1754 线段树点修改
摘要:1 #include 2 int ql,qr,p,v,minv[1000005]; 3 int max(int x,int y) 4 { 5 if (x>y) return(x); 6 return(y); 7 } 8 int qu... 阅读全文

posted @ 2014-07-16 17:34 xiao_xin 阅读(93) 评论(0) 推荐(0)

1

导航