摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1698大意:给一组棍子染色,不同的颜色有不同的值,执行一系列的区间染色后,问这组棍子的总值是多少。题目分析:建树:节点的域有左右节点和颜色,l,r,num;num=0时表示这个区间由多种颜色覆盖。更新的时候,如果更新区间比当前区间小,并且当前区间的颜色大于0,说明已经被完全染色,就把该区间颜色传递到左右子树上,该区间染色为0,然后根据更新区间的大小,在左右子树上去搜索。求和的时候遇到区间的num>0的时候说明完全被染色过了,就把区间的长度乘以颜色的值加到总和里面去,然后结束这个方向的递归查询,代码:#i 阅读全文
posted @ 2012-11-23 12:21 紫忆 阅读(352) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1754View Code #include<iostream>using namespace std;struct{ int l,r,max;}s[200005*4];int data[200005];void build(int l,int r,int n){ int mid=(l+r)/2; if(l==r) { s[n].l=l; s[n].r=r; s[n].max=data[l]; } else { s... 阅读全文
posted @ 2012-11-23 08:49 紫忆 阅读(164) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1255http://acm.hdu.edu.cn/showproblem.php?pid=1542思路:嗯哼,要开始利用线段树求解矩形面积的并、交、以及周长了。先看一下吧给定一个矩形的左下角坐标和右上角坐标分别为:(x1,y1)、(x2,y2),对这样的一个矩形,我们构造两条线段,一条定位在x1,它在y坐标的区间是[y1,y2],并且给定一个cover域值为1;另一条线段定位在x2,区间一样是[y1,y2],给定它一个cover值为-1。根据这样的方法对每个矩形都构造两个线段,最后将所有的线段根据所定位的x从 阅读全文
posted @ 2012-11-23 08:47 紫忆 阅读(440) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1166用线段树做,比树状数组费时#include<iostream>using namespace std;const int N=50005;struct { int left,right,num;}s[4*N];int data[N];void build(int left,int right,int n){ int mid; mid=(left+right)/2; if(left==right) { s[n].left=left; s[n].ri... 阅读全文
posted @ 2012-11-23 08:40 紫忆 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 如果给定一个数组,要你求里面所有数的和,一般都会想到累加。但是当那个数组很大的时候,累加就显得太耗时了,时间复杂度为O(n),并且采用累加的方法还有一个局限,那就是,当修改掉数组中的元素后,仍然要你求数组中某段元素的和,就显得麻烦了。所以我们就要用到树状数组,他的时间复杂度为O(lgn),相比之下就快得多。下面就讲一下什么是树状数组:一般讲到树状数组都会少不了下面这个图:下面来分析一下上面那个图看能得出什么规律:据图可知:c1=a1,c2=a1+a2,c3=a3,c4=a1+a2+a3+a4,c5=a5,c6=a5+a6,c7=a7,c8=a1+a2+a3+a4+a5+a6+a7+a8,c9= 阅读全文
posted @ 2012-11-22 16:39 紫忆 阅读(371) 评论(0) 推荐(0) 编辑
摘要: http://acm.hust.edu.cn:8080/judge/problem/viewProblem.action?id=15025#include<iostream>#include<algorithm>using namespace std;struct node{ __int64 f,v;}str[500000];__int64 c[500000],n,t[500000];int cmp(const node &a,const node &b){ if(a.f<b.f) return 1; else return 0;}__int64 阅读全文
posted @ 2012-11-22 16:31 紫忆 阅读(302) 评论(0) 推荐(0) 编辑
摘要: http://acm.hust.edu.cn:8080/judge/problem/viewProblem.action?id=10588思路:先对E进行降序排序,在E相等的情况下,对S进行升序排序。然后用树状数组统计即可#include<iostream>#include<algorithm>using namespace std;struct node { int s,e,k;}t[100005];int c[100005];int cmp(const node &a,const node &b){ if(b.e<a.e) return 1; 阅读全文
posted @ 2012-11-22 16:26 紫忆 阅读(167) 评论(0) 推荐(0) 编辑
摘要: http://acm.hust.edu.cn:8080/judge/problem/viewProblem.action?id=11104此题比较坑爹,离散化中,相等的数进行离散化后也需要相等对于相等数据的离散化,可以采用赋值相同的值来处理对于相等数据的离散化,可以采用赋值相同的值来处理#include<iostream>#include<algorithm>using namespace std;__int64 c[70000],n,t[70000];struct node{ __int64 v,f;}s[70000];int cmp(const node & 阅读全文
posted @ 2012-11-22 16:20 紫忆 阅读(364) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2688#include<algorithm> using namespace std;const int maxn=10005;const int maxm=3000005;int c[maxn],a[maxm],n;int sum(int x){ int s=0; while(x>=1) { s+=c[x]; x-=x&(-x); } return s;}void updata(int i){ while(i<=maxn-1) { c[i]++; i+=i&(-i); 阅读全文
posted @ 2012-11-22 16:12 紫忆 阅读(223) 评论(0) 推荐(0) 编辑
摘要: 1 #include<iostream> 2 using namespace std; 3 int a[1010][1010],c[1010][1010],n=1005; 4 int lowbit(int x) 5 { 6 return x&(-x); 7 } 8 int sum(int x,int y) 9 { 10 int i,j,sum=0; 11 for(i=x;i>0;i-=lowbit(i)) 12 { 13 for(j=y;j>0;j-=lowbit(j)) 14 { 15 ... 阅读全文
posted @ 2012-11-22 16:04 紫忆 阅读(194) 评论(0) 推荐(0) 编辑