[ACM_数据结构] POJ2352 [树状数组稍微变形]
Description
For example, look at the map shown on the figure above. Level of the star number 5 is equal to 3 (it's formed by three stars with a numbers 1, 2 and 4). And the levels of the stars numbered by 2 and 4 are 1. At this map there are only one star of the level 0, two stars of the level 1, one star of the level 2, and one star of the level 3. You are to write a program that will count the amounts of the stars of each level on a given map.
Input
Output
Sample Input
5
1 1
5 1
7 1
3 3
5 5
Sample Output
1
2
1
1
0
#include<iostream>
#include<cstdio>
#include<memory.h>
using namespace std;
#define maxn 32100//是叶节点能达到的最大值多一点
int C[maxn];//从1开始编号
//--------------------------
int lowbit(int x){
return x&-x;
}
int sum(int x){
int ret=;
while(x>){
ret+=C[x];
x-=lowbit(x);
}
return ret;
}
void add(int x,int d){
while(x<=maxn){
C[x]+=d;
x+=lowbit(x);
}
}
//--------------------------
/*
给定n个点,问这一点左下角的区域的点的个数,不包括这一点
因为输入是按照y从小到达,然后是按x从小到达,且x不同
因此先出现的肯定比后出现的y小即在后出现的点之下,
因此只要把x作为树状数组下标就可以啦。然后用一个out[num]维护
个数为num的点的数量
*/
int out[maxn];
int main(){
int n;
while(scanf("%d",&n)!=EOF){
int x,y;
int i,j;
memset(out,,sizeof(out));
memset(C,,sizeof(C));
for(i=;i<=n;i++){
scanf("%d%d",&x,&y);
out[sum(x+)]++;
add(x+,);
}
for(i=;i<n;i++){
printf("%d\n",out[i]);
}
}
return ;
}
[ACM_数据结构] POJ2352 [树状数组稍微变形]的更多相关文章
- Codeforces Round #248 (Div. 2) B称号 【数据结构:树状数组】
主题链接:http://codeforces.com/contest/433/problem/B 题目大意:给n(1 ≤ n ≤ 105)个数据(1 ≤ vi ≤ 109),当中有m(1 ≤ m ≤ ...
- poj2352树状数组
Astronomers often examine star maps where stars are represented by points on a plane and each star h ...
- poj2352树状数组解决偏序问题
树状数组解决这种偏序问题是很厉害的! /* 输入按照y递增,对于第i颗星星,它的level就是之前出现过的星星中,横坐标小于i的总数 */ #include<iostream> #incl ...
- 数据结构(树状数组):HEOI2012 采花
[题目描述] 萧薰儿是古国的公主,平时的一大爱好是采花. 今天天气晴朗,阳光明媚,公主清晨便去了皇宫中新建的花园采花.花园足够大,容纳了n朵花,花有c种颜色(用整数1-c表示),且花是排成一排的,以便 ...
- [poj 1533]最长上升子序列nlogn树状数组
题目链接:http://poj.org/problem?id=2533 其实这个题的数据范围n^2都可以过,只是为了练习一下nlogn的写法. 最长上升子序列的nlogn写法有两种,一种是变形的dp, ...
- 【poj 3167】Cow Patterns(字符串--KMP匹配+数据结构--树状数组)
题意:给2个数字序列 a 和 b ,问按从小到达排序后,a中的哪些子串与b的名次匹配. a 的长度 N≤100,000,b的长度 M≤25,000,数字的大小 K≤25. 解法:[思考]1.X 暴力. ...
- cdoj841-休生伤杜景死惊开 (逆序数变形)【线段树 树状数组】
http://acm.uestc.edu.cn/#/problem/show/841 休生伤杜景死惊开 Time Limit: 3000/1000MS (Java/Others) Memory ...
- 牛客练习赛22-E.简单数据结构1(扩展欧拉定理降幂 +树状数组)
链接:E.简单数据结构1 题意: 给一个长为n的序列,m次操作,每次操作: 1.区间加 2.对于区间,查询 ,一直到- 请注意每次的模数不同. 题解:扩展欧拉定理降幂 对一个数p取log(p)次的 ...
- 「BZOJ1537」Aut – The Bus(变形Dp+线段树/树状数组 最优值维护)
网格图给予我的第一反应就是一个状态 f[i][j] 表示走到第 (i,j) 这个位置的最大价值. 由于只能往下或往右走转移就变得显然了: f[i][j]=max{f[i-1][j], f[i][j-1 ...
随机推荐
- C#aspx页面前台使用<%=%>无法取到后台的值
检查是不是有拼接问题,正常public和protected修饰的字段或属性均可使用<%=%>.另外,加载(Page_Load)时有没有给它们赋初始值? 答 1)前台页面只能调用本后置代码的 ...
- unity profiler - Loading.ReadObject
关于Loading.ReadObject耗费比较高,有什么推荐的方法吗? Loading.ReadObject是Unity引擎的资源加载函数,一般出现在切换场景和加载API调用时,这其中包括纹理.网格 ...
- [leetcode]215. Kth Largest Element in an Array 数组中第k大的元素
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...
- 7-掉馅饼(数组dp)
/* 免费馅饼 时间限制:1000 ms | 内存限制:65535 KB ...
- struts框架问题四之获取到值栈的对象
4. 问题四 : 如何获得值栈对象 * 获得值栈对象 有三种方法 * ValueStack vs1 = (ValueStack) ServletActionContext.getRequest().g ...
- 使用jmeter工具测试上传接口
1.方法选择post:上传都是post上传. 2.路径输入正确的上传接口路径,并勾选Use multipart/form-data for POST 3.添加文件,文件路径尽量不要有中文,防止编码问题 ...
- 只有自己看的懂的vue 二叉树的3级联动
我是在vue做的数据 actions mutations state index页面获取值 传递给子页面 子页面的操作 <template> <div class='cascade_ ...
- python编辑excel
转: http://www.cnblogs.com/lhj588/archive/2012/01/06/2314181.html
- Luogu 2154 [SDOI2009]虔诚的墓主人
弄了很久,状态很烂…… 首先发现可用的点一共只有$1e5$个,所以可以离散化坐标来方便计算. 发现对于一个空格,设它的上.下.左.右分别有$u, d, l, r$个点,它产生的贡献是$\binom{u ...
- 关闭文件描述符-close
头文件:#include<unistd.h> 原型:int close(int fd); 返回值:成功返回0,失败返回-1.