poj2352Stars(树状数组)
来源:互联网 发布:百乐官方淘宝授权店 编辑:程序博客网 时间:2024/05/02 01:04
分析:由于输入数据是以y为第一关键递增输入,以x为第二关键字递增输入,因此,可以直接对x用一维树状数组。
#include<stdio.h>#include<string.h>int count[32005];int c[32005];int lowbit(int x){return x&(-x);}void change(int x){int i;for(i=x;i<32005;i+=lowbit(i))c[i]++;}int sum(int x){int i,sum=0;for(i=x;i>0;i-=lowbit(i))sum+=c[i];return sum;}int main(){memset(count,0,sizeof(count));memset(c,0,sizeof(c));int x,y,i,n;scanf("%d",&n);for(i=0;i<n;i++){scanf("%d %d",&x,&y);x++;//不能少了这行,否则出现x=0时change会出现死循环,导致超时count[sum(x)]++;change(x);}for(i=0;i<n;i++)printf("%d\n",count[i]);return 0;}
- poj2352Stars(树状数组)
- POJ2352Stars(树状数组)
- (转)树状数组
- 树状数组(转载)
- Stars(树状数组)
- 树状数组(interval)
- (转)树状数组
- 树状数组(2)
- 树状数组(3)
- 树状数组(4)
- 树状数组(5)
- 树状数组(6)
- POJ2299(树状数组)
- hdu2492 (树状数组)
- 树状数组()
- LA4329(树状数组)
- poj3468(树状数组)
- 【树状数组(一)】
- NSNotification
- 常量指针和指针常量
- 题目1155:鸡兔同笼
- BeanShell方法实现详解
- Invalid result location value/parameter 解决办法
- poj2352Stars(树状数组)
- 序列化(Serialize)和反序列化(Deserialize)
- #Sam有话说#找准你的style
- ACM搜索题目总结
- iptables简单使用
- 关于ExtJS-4.0.2a中在gridpanel中出现column.getEditor is not a function的错误解决方法
- ubuntu12.10上针对NS2-2.35的tcl-debug-2.0的安装
- poj 1005 I Think I Need a Houseboat
- python之import机制