随笔分类 - 树状数组
摘要:http://poj.org/problem?id=2892题意:输入n,m。n代表数轴的长度,m代表操作数。 D x: 摧毁点x Q x: 询问村庄x最左与最右没有被摧毁的点的距离R :恢复最后一个被摧毁的点 1 #include 2 #include 3 const int N=50001; 4 int c[N],keep[N],n; 5 bool vis[N]; 6 7 int lowbit(int x) 8 { 9 return x&(-x);10 }11 int sum(int x)12 {13 int res = 0;14 while(x > 0)15...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1166树状数组模板题 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 const int N=50005; 7 int a[N],c[N]; 8 int n; 9 int lowbit(int x)10 {11 return x&(-x);12 }13 int sum(int x)14 {15 int ans = 0;16 while(x > 0)17 {18 an...
阅读全文
摘要:http://poj.org/problem?id=2352题意:给出每个星星在平面内的坐标(x,y)(y递增,y相同时,x递增)。每颗星星的级别定义为,横纵坐标均不超过自己的星星个数(不包括自己),求级别为0~N-1的星星分别有多少个。 1 #include 2 const int N=32001; 3 int n,c[N],level[N]; 4 int lowbit(int x) 5 { 6 return x&(-x); 7 } 8 int sum(int x)//求和 9 {10 int s = 0;11 while(x>0)12 {13 ...
阅读全文

浙公网安备 33010602011771号