树状数组 求区间和
摘要:
1 #include <stdio.h> 2 #include <string.h> 3 int N,a[60000]; 4 int lowbit(int x) 5 { 6 7 return x&(-x); 8 } 9 void add(int i,int x)10 {11 while(i<=N)12 {13 a[i]+=x;14 i+=lowbit(i);15 }16 }17 int sum(int i)18 {19 int sum=0;20 while(i)21 {22 sum+=a[i];23 i-=lowbit(i);24 }25 return s 阅读全文
posted @ 2011-08-15 19:27 more think, more gains 阅读(232) 评论(0) 推荐(0) 编辑