hdu1541 Stars 树状数组
来源:互联网 发布:男 休闲鞋类推荐 知乎 编辑:程序博客网 时间:2024/05/17 02:26
/************************* * Author:fisty * Data:2014-12-8 * 树状数组求正序数 * **********************/#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define MAX_N 330020typedef long long ll;int bit[MAX_N];int sum(int i){ //sum求和 int sum = 0; while(i > 0){ sum += bit[i]; i -= i&-i; } return sum;}void add(int i,int x){ //在i位加x while(i <= MAX_N){ bit[i] += x; i += i&-i; }}struct node{ int x,y;}a[MAX_N];void solve(int n){ int ans[MAX_N]; memset(ans, 0, sizeof(ans)); //树状数组求正序数 for(int i = 0;i < n; i++){ ans[sum(a[i].x)]++; //求每层的个数 add(a[i].x, 1); } for(int i = 0;i < n; i++){ printf("%d\n", ans[i]); }} int main(){ int n; while(scanf("%d", &n) != EOF){ memset(bit, 0, sizeof(bit)); for(int i = 0;i < n; i++){ scanf("%d%d",&a[i].x, &a[i].y); a[i].x++; //在树状数组里不可以有0下标,故把坐标全部加1 } solve(n); } return 0;}
0 0
- hdu1541 Stars (树状数组)
- hdu1541 Stars 树状数组
- HDU1541 Stars【树状数组】
- hdu1541-Stars(树状数组)
- HDU1541 Stars 树状数组
- HDU1541 Stars (树状数组)
- HDU1541 Stars (树状数组)
- hdu1541 Stars(树状数组)
- HDU1541 Stars(树状数组)
- poj2352 && hdu1541 Stars(树状数组)
- HDU1541--Stars(树状数组)
- POJ 2352 HDU1541 Stars(树状数组)
- hdu1541 Stars 树状数组水题
- POJ 2352 HDU1541 Stars(树状数组)
- hdu1541 Stars(树状数组+解释)
- ACM-树状数组之Stars——hdu1541,poj2352
- hdu3792(Twin Prime Conjecture) and hdu1541(Stars)树状数组
- 【树状数组--单点更新区间求和】 hdu1541 Stars
- 第十四周项目五:体会棋盘游戏中的数据储存
- MySql中执行sql脚本文件
- word使用笔记
- Content Provider
- 常用linux命令记录 修改乱码
- hdu1541 Stars 树状数组
- Oracle 获取日期的周数
- spring security 3.2: HelloWorld
- js页面跳转常用的几种方式
- matlab直接保存图形而不显示图形
- Android NDK开发(一)——环境搭建
- 2013奇虎360校招笔试题—2011.10.9
- js获取url参数值
- 从今天开始写这个博客