POJ 2352 Stars 树状数组
来源:互联网 发布:软件开发工作计划范文 编辑:程序博客网 时间:2024/06/05 10:25
原题链接
由于是求左下角的总数,且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 starsint 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;}
阅读全文
0 0
- POJ 2352 Stars 树状数组
- POJ 2352 Stars【树状数组】
- (树状数组) poj 2352 Stars
- POJ-2352-Stars-树状数组
- POJ 2352 Stars 树状数组
- POJ 2352 Stars 【树状数组】
- POJ 2352 Stars 树状数组
- POJ-2352 Stars【树状数组】
- POJ 2352 Stars 树状数组
- poj 2352 Stars 树状数组
- poj 2352 Stars 树状数组
- POJ:2352 Stars(树状数组)
- [树状数组]POJ 2352 Stars
- POJ-2352-Stars 树状数组
- Stars - POJ 2352 树状数组
- poj 2352 Stars 树状数组
- poj 2352 Stars (树状数组)
- POJ 2352 Stars【树状数组】
- C#开发WinForm窗体程序时,如何在子窗体中关闭窗口时并退出程序?
- longest substring
- canvas学习笔记一
- clang: error: linker command failed with exit code 1 (use -v to see invocation)
- 各种二叉树和查找结构总结
- POJ 2352 Stars 树状数组
- 【Ex.】右翻转指定的字符串以及对比特位置零或置1操作例题代码
- 京东算法题---求幂
- WebForm.aspx 页面通过 AJAX 访问WebForm.aspx.cs类中的方法,获取数据(转)
- JavaScript 操作 Cookie
- 欢迎使用CSDN-markdown编辑器
- 使用PL/SQL内置的DBMS_SQL包执行动态SQL
- ubuntu 12.04 下DHCP网络设置——链接外网(NAT模式)
- 4