上一页 1 ··· 22 23 24 25 26
摘要: 二维树状数组:同样不要忘记c的初始化,modify的功能是改变元素(x,y),sum的功能则是求从元素(1,1)开始到(x,y)的总和,同样,可以求出任意一个子矩阵内的所有元素之和,即sum(x2,y2)-sum(x1-1,y2)-sum(x2,y1-1)+sum(x1-1,y1-1)intlowbit(intx){returnx&(-x);}voidmodify(intx,inty,intdelta){inti,j;for(i=x;i<=N;i+=lowbit(i)){for(j=y;j<=N;j+=lowbit(j)){c[i][j]+=delta;}}}intsum( 阅读全文
posted @ 2012-11-22 16:01 紫忆 阅读(158) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1541题意:给定一些点,求在这点左下方的点的个数;思路:此题可以用二维树状数组做,但仔细看题,可以得到给出的y是从小到大的,这样,只需对x进行操作,进而转换为在x左边的点有多少个代码:#include<iostream>using namespace std;int a[32005],c[32005],n=32005;int lowbit(int x){ return x&(-x);}int sum(int x){ int sum=0; while(x>0) { sum+=c[x]; 阅读全文
posted @ 2012-11-22 15:59 紫忆 阅读(389) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1394题意:求最小逆序数#include<iostream>using namespace std;int c[5005],n,a[5005];int lowbit(int x){ return x&(-x);}int sum(int x){ int sum=0; while(x>0) { sum+=c[x]; x-=lowbit(x); } return sum;}void inster(int x,int i){ while(x<=n) { c[x]+=i; x+=lowb 阅读全文
posted @ 2012-11-22 15:52 紫忆 阅读(254) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2838思路:对于数据3,4,1,2先按顺序建树,updata(a[i],a[i]),s+=a[i];当i=3时,1前面有3,4比1大,这时,先求出比1等于或小的元素和,在用s-sum(1),结果为,1前面比1大的元素和。代码:View Code 1 #include<iostream> 2 using namespace std; 3 __int64 a[100005],c[100005],d[100005],n; 4 int lowbit(int x) 5 { 6 return x&(- 阅读全文
posted @ 2012-11-22 15:48 紫忆 阅读(238) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2689代码:#include<iostream>using namespace std;int c[1010],a[1010],n;int lowbit(int x){ return x&(-x);}int sum(int x){ int sum=0; while(x>0) { sum=sum+c[x]; x-=lowbit(x); } return sum;}void inster(int x,int i){ while(x<=n) { c[x]+=i; x+=lowbit( 阅读全文
posted @ 2012-11-22 15:32 紫忆 阅读(250) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1556代码:#include<iostream>int n,c[100003];int lowbit(int x){ return x&(-x);}int sum(int x){ int sum=0; while(x>0) { sum+=c[x]; x-=lowbit(x); } return sum;}void inster(int x,int i){ while(x<=n) { c[x]+=i; x+=lowbit(x); }}int main(){ int a,b,i; 阅读全文
posted @ 2012-11-22 15:27 紫忆 阅读(869) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1166代码:#include<iostream>using namespace std;int n,a[50005],c[50005];int lowbit(int x){ return x&(-x);}int sum(int x){ int sum=0; while(x>0) { sum+=c[x]; x=x-lowbit(x); } return sum;}void inster(int i,int j){ while(i<=n) ... 阅读全文
posted @ 2012-11-22 15:23 紫忆 阅读(170) 评论(0) 推荐(0) 编辑
摘要: Ping pongTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2242Accepted Submission(s): 823Problem DescriptionN(3<=N<=20000) ping pong players live along a west-east street(consider the street as a line segment). Each player has a unique skill r 阅读全文
posted @ 2012-11-22 15:18 紫忆 阅读(534) 评论(0) 推荐(0) 编辑
上一页 1 ··· 22 23 24 25 26