POJ2352(树状数组)
2013-07-09 21:07
211 查看
#include <iostream> using namespace std; int c[32001]={0}; int lowbit(int x) { return x&(-x); } int getsum(int x) { int total=0; while (x>0) { total+=c[x]; x-=lowbit(x); } return total; } void update(int index) { while (index<=32001) { c[index]+=1; index+=lowbit(index); } } int main() { int T; int x,y; int hash[15000]={0}; scanf("%d",&T); int n=T; while (T--) { scanf("%d%d",&x,&y); update(x+1); hash[getsum(x+1)-1]++; } int i; for (i=0;i<=n-1;i++) { printf("%d\n",hash[i]); } return 0; }特别注意: 坐标是从(0,0)开始的而一般树状数组的下标是从1开始的,将坐标+1后再进行操作,否则会出错。
相关文章推荐
- POJ 3416——Crossing(两个树状数组,poj2352)
- 树状数组简单题(POJ2352,HDU1541)
- poj2352 Stars(树状数组)
- 【poj2352】【树状数组】Stars
- 【树状数组】poj2352 stars
- POJ2352 简单树状数组 附加输入挂
- POJ2352 Stars 【树状数组】or【线段树】
- 简单树状数组-poj2352
- ACM集训——POJ2352---一维树状数组的应用
- POJ2352(树状数组)
- 【POJ2352】【树状数组】Stars
- POJ2352-Stars(树状数组模板)
- poj2352之树状数组
- POJ2352:Stars(树状数组)
- POJ2352 Stars 树状数组 + 裸
- 树状数组专题(一)POJ2352
- ACM-树状数组之Stars——hdu1541,poj2352
- POJ2352 stars(树状数组)
- [POJ2352] Stars(树状数组)
- POJ2352 Stars(树状数组)