hdu-1541 Stars----- 树状数组
生活随笔
收集整理的這篇文章主要介紹了
hdu-1541 Stars----- 树状数组
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
此題由于有可能出現坐標為 0 的點,而我們用的樹狀數組則從1開始,所以做題的時候要注意
#include<stdio.h> #include<string.h> #define M 32002 int a[M]; int c[M]; int n; int lowbit(int x) {return x&(-x); } void add(int pos,int num) {while(pos <= M - 1){a[pos] += num;pos += lowbit(pos);} } int get_sum(int pos) {int res = 0;while(pos > 0){res += a[pos];pos -= lowbit(pos);}return res; } int main() {int x,y;while(scanf("%d",&n)!=EOF){memset(a,0,sizeof(a));memset(c,0,sizeof(c));int ans;for(int i = 1;i <= n;i++){scanf("%d%d",&x,&y);ans = get_sum(x+1);c[ans] ++;add(x+1,1);}for(int i = 0;i < n;i++){printf("%d\n",c[i]);}} }總結
以上是生活随笔為你收集整理的hdu-1541 Stars----- 树状数组的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 腾讯总监周颢:亿级用户微信采用的架构宝典
- 下一篇: PerfMa“寒泉子”李嘉鹏:成长和创业