2011年8月6日
摘要: 题目解决方案一:线段树 1916ms 47100B C/C++可以看到用线段树解决非常的浪费空间#include <iostream>#include <cstdio>using namespace std;#define L(x) (x<<1)#define R(x) ((x<<1)+1)#define M(x,y) ((x+y)>>1)const int N=1000005;struct node{ int l,r,score;};node tree[4*N];/*此处建立的线段树为[a,b][b+1,c]类型,由于询问的是点的大 阅读全文
posted @ 2011-08-06 20:06 猿类的进化史 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 题目描述解决方案一:用线段树解决,因为查询的是某区间的最值时间1396 空间 5304代码长度75#include <iostream>#include <algorithm>#include <cstdio>using namespace std;struct node{ int l,r,min,max;};const int N=100005;int num[N];#define L(x) (x<<1)#define R(x) ((x<<1)+1)#define M(x,y) ((x+y)>>1)node tree[4 阅读全文
posted @ 2011-08-06 16:16 猿类的进化史 阅读(260) 评论(0) 推荐(0) 编辑
摘要: 题目解决:(树状数组)本题是树状数组的基本应用符合两个特征,1、求区间和 2、修改的是单个元素 #include <iostream> #include <cstdio>using namespace std;const int N=1000005;int c[N];int n;//该函数功能是求出n二进制中最右边0的个数的2次幂,也等于c[n]包含的元素个数num[n-lowbit(n)+1]+...+num[n]int lowbit(int n){ return n&(-n);}//更新数组中pos的值使它加上inc,更新首先更新c[pos]一直更新该点的父 阅读全文
posted @ 2011-08-06 15:08 猿类的进化史 阅读(236) 评论(0) 推荐(0) 编辑
摘要: poj 3468题目大意:给定Q(1 ≤ Q≤ 100,000)个数A1,A2… AQ,,以及可能多次进行的两个操作:1)对某个区间Ai … Aj的个数都加n(n可变)2) 求某个区间Ai … Aj的数的和2) 求某个区间Ai … Aj的数的和解决:线段树/*线段树的区间有两种形式,第一种是[1,2][2,3],第二种是[1,1],[2,2],在这里,由于我们查询的区间和是不能相交的,所以只能采用第二中形式,*/#include <iostream>#include <cstdio>using namespace std;typedef long long intt;s 阅读全文
posted @ 2011-08-06 10:15 猿类的进化史 阅读(357) 评论(0) 推荐(0) 编辑