Stars(树状数组单点更新)
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
5 5
Sample Output
1
2
1
1
0
Hint
#include <cstdio>
#include <cstring>
const int MAXN=1e5+;
int c[MAXN],a[MAXN];//a[]是哈希数数组,用来统计每个等级的数量
int m,t;
int Lowbit(int x)
{
return x&(-x);
}
void update(int i, int x)//向上更新
{
while(i <= )
{
c[i] += x;
i += Lowbit(i);
}
}
int Getsum(int x)//向下求和
{
int sum=;
while(x>)
{
sum+=c[x];
x-=Lowbit(x);
}
return sum;
}
int main()
{
int m,x,b;
while(scanf("%d",&m)!=-)
{
int k=m;
memset(a,,sizeof());
memset(c,,sizeof());
while(k--)
{
scanf("%d%d",&x,&b);
a[Getsum(x+)]++;//用getsome()来计算在该星星前有多少个星星即是它的等级,a[]是哈希数组
update(x+,);//把该点更新
}
for(int i=; i<m; i++)
{
printf("%d\n",a[i]);
}
}
return ;
}
Stars(树状数组单点更新)的更多相关文章
- hdu   2642二维树状数组 单点更新区间查询 模板题
		二维树状数组 单点更新区间查询 模板 从零开始借鉴http://www.2cto.com/kf/201307/227488.html #include<stdio.h> #include& ... 
- TZOJ 2725 See you~(二维树状数组单点更新区间查询)
		描述 Now I am leaving hust acm. In the past two and half years, I learned so many knowledge about Algo ... 
- poj3321 dfs序+树状数组单点更新 好题!
		当初听郭炜老师讲时不是很懂,几个月内每次复习树状数组必看的题 树的dfs序映射在树状数组上进行单点修改,区间查询. /* 树状数组: lowbit[i] = i&-i C[i] = a[i-l ... 
- SPOJ - MATSUM 二维树状数组单点更新
		忘记了单点更新时要在树状数组中减去原值..wa了一发 /* 矩形求和,单点更改 */ #include<iostream> #include<cstring> #include ... 
- 牛客小白月赛6 F 发电 树状数组单点更新 求区间乘积 模板
		链接:https://www.nowcoder.com/acm/contest/136/F来源:牛客网 HA实验是一个生产.提炼“神力水晶”的秘密军事基地,神力水晶可以让机器的工作效率成倍提升. ... 
- hdu 2642 二维树状数组 单点更新区间查询 模板水题
		Stars Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others) Total Subm ... 
- hdu2642二维树状数组单点更新+区间查询
		http://acm.hdu.edu.cn/showproblem.php?pid=2642 题目大意:一个星空,二维的.上面有1000*1000的格点,每个格点上有星星在闪烁.一开始时星星全部暗淡着 ... 
- POJ 2828 Buy Tickets(线段树 树状数组/单点更新)
		题目链接: 传送门 Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Description Railway tickets were d ... 
- hdu2642二维树状数组单点更新
		碰到这种题一定要注意坐标是不是有序的,也要注意坐标是不是有0的,有的话需要+1处理 #include<bits/stdc++.h> using namespace std; #define ... 
随机推荐
- SurfaceView基本使用--动态画正弦函数
			package com.zzw.TestSurfaceView; import android.content.Context; import android.graphics.Canvas; imp ... 
- mysql中delete的表别名使用方法
			在 mapper.xml 中的 dynamicWhere 动态查询中使用了表别名,Delete 语句引用了动态查询,如下: <delete id="delete" param ... 
- iOS编译集成linux开源c库的一些记录
			最近一个iOS项目需要使用一些Linux下面的开源c库,说是Linux的其实是跨平台的,各种Unix系统都有支持.理论上iOS来自MacOS,而MacOS其实是一种兼容的Unix系统,所以这些库应该也 ... 
- python中的赋值与拷贝(浅拷贝与深拷贝)
			1.赋值与拷贝 直接赋值(b=a)是传引用,b改动a也会改动. a = [1, 2, 3, 4] b = a b[1] = 999 print(a, b) #[1, 999, 3, 4] [1, 99 ... 
- How your script code be coverted into arm code  and running on ios.
			Your script code is compiled into DLLs (assemblies) by the editor. When you build for iOS, these ass ... 
- 利用Python进行文章特征提取(一)
			# 文字特征提取 词库模型(bag of words) 2016年2月26,星期五 # 1.词库表示法 In [9]: # sklearn 的 CountVectorizer类能够把文档词块化(tok ... 
- 前端之JavaScript再次补充(干死!!)
			<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ... 
- Python之MySQLdb
			MySQLdb是用于Python链接Mysql数据库的接口,它实现了Python数据库API规范V2.0,基于MySql C API上建立的. 1. MySQLdb安装 (1)安装Mysql,参考上篇 ... 
- MyEclipse2014快速配置Spring & Spring Testing, Spring AOP简单使用
			1.新建项目 2.右击项目,如图,利用myeclipse自动导入spring 3.在弹出的对话框中一直next到最后,在最后的页面中勾选Spring Testing,完成. 4.在src下的appli ... 
- hibernate正向工程生成数据库
			hibernate正向工程生成数据库 hibernate.cfg.xml ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 2 ... 
