POJ 2352 Stars 树状数组
2017-09-10 11:01
337 查看
原题链接
由于是求左下角的总数,且y输入从小到大,满足前缀和,故使用树状数组
由于是求左下角的总数,且y输入从小到大,满足前缀和,故使用树状数组
#include <stdio.h> #include <string.h> #define lowbit(x) (x&(-x)) const int maxn=15010,maxx=32010; int C[maxx],N,ans[maxn],x,y; ///the level of stars int sum(int x){ int ans=0; while(x>0){ ans+=C[x]; x-=lowbit(x); } return ans; } void add(int x){ while(x<=maxx){ C[x]++; x+=lowbit(x); } } int main() { scanf("%d",&N); memset(ans,0,sizeof(ans)); memset(C,0,sizeof(C)); for(int i=0;i<N;i++){ scanf("%d%d",&x,&y); ans[sum(x+1)]++;///because x can equal 0, and array C need x>=1, so use x+1 add(x+1); } for(int i=0;i<N;i++) printf("%d\n",ans[i]); return 0; }
相关文章推荐
- poj 2352 stars 树状数组
- POJ-2352-Stars-树状数组
- poj 2352 Stars 树状数组
- POJ 2352 Stars 树状数组
- poj2352 Stars (第一道树状数组
- Stars - POJ 2352 树状数组
- POJ 2352 stars 树状数组
- POJ 2352 Stars & UESTC 1584 Washi与Sonochi的约定 排序+树状数组
- POJ 2352 Stars | 树状数组
- poj 2352 Stars 树状数组
- POJ2352 Stars 树状数组
- POJ 2352 Stars 树状数组
- poj2352+2481 stars+cows 树状数组
- POJ 2352 Stars 初学树状数组
- poj 2352 Stars(线段树||树状数组)
- POJ 2352_Stars && POJ-2481 Cows (线段树单点更新+树状数组)
- 求左下角星星之和 树状数组或线段树 poj 2352 Stars
- poj 2352 Stars 树状数组
- poj 2352 Stars--树状数组
- POJ 2352 Stars 解题思路,树状数组