HD1556Color the ball(树状数组)
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13645 Accepted Submission(s): 6850
当N = 0,输入结束。
1 1
2 2
3 3
3
1 1
1 2
1 3
0
3 2 1
树状数组搞定的第一题!
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAX = + ;
int c[MAX];
int n;
int lowbit(int k)
{
return k & (-k);
}
void update(int x,int num)
{ while(x <= n)
{
c[x] += num;
x += lowbit(x);
}
}
int sum(int x)
{
int s = ;
while(x > )
{
s += c[x];
x -= lowbit(x);
}
return s;
}
int main()
{
while(scanf("%d", &n) && n)
{
int a,b;
memset(c,,sizeof(c));
for(int i = ; i < n; i++)
{
scanf("%d%d",&a,&b);
update(a,);
update(b + ,-);
}
printf("%d",sum());
for(int i = ; i <= n; i++)
printf(" %d",sum(i));
printf("\n");
}
return ;
}
HD1556Color the ball(树状数组)的更多相关文章
- Color the ball(树状数组+线段树+二分)
Color the ball Time Limit : 9000/3000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
- HDOJ/HDU 1556 Color the ball(树状数组)
Problem Description N个气球排成一排,从左到右依次编号为1,2,3-.N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动车从 ...
- HDU 1556 Color the ball (树状数组区间更新)
水题,练习一下树状数组实现区间更新. 对于每个区间,区间左端点+1,右端点的后一位-1,查询每个位置的覆盖次数 #include <cstdio> #include <cstring ...
- HDU 1556 Color the ball 树状数组 题解
Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动 ...
- Codeforces Beta Round #12 (Div 2 Only) D. Ball 树状数组查询后缀、最值
http://codeforces.com/problemset/problem/12/D 这里的BIT查询,指的是查询[1, R]或者[R, maxn]之间的最值,这样就够用了. 设三个权值分别是b ...
- hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 4602 Magic Ball Game(离线处理,树状数组,dfs)
Magic Ball Game Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 4605 Magic Ball Game(可持续化线段树,树状数组,离散化)
Magic Ball Game Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- hdoj--1556--Color the ball(模拟&&树状数组)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
随机推荐
- HTML5+JS 《五子飞》游戏实现(八)人机对战
要想实现人机对战,就必须让电脑自动下棋,而且要知道自动去查找对方的棋子,看看有没有可以挑一对的,有没有可以夹一个的,这样下起来才有意思. 当电脑用户下完棋后,电脑应立即搜索用户的棋子,然后如果没有被吃 ...
- 曼慧尼特u检验(两个样本数据间有无差异)
曼-惠特尼U检验(Mann-Whitney检验) How the Mann-Whitney test works Mann-Whitney检验又叫做秩和检验,是比较没有配对的两个独立样本的非参数检验. ...
- MVC-通过对象获取整个表单内容
-------- 在MVC的Controller(控制器)里面定义相同的方法时,我们需要解决重载问题: 解决方案一:在参数中定义一个FormCollection类型,解决问题 [HttpSet] pu ...
- eclipse技巧总结
如果遇到错误或警告,先试试统一的方法:在problems view中,右键error或者warnning,选择quick fix serial ID并不常用,如果不实现它,eclipse会给出一 ...
- 【JavaEE企业应用实战学习记录】requestListener
package sanglp.servlet; import javax.servlet.*; import javax.servlet.annotation.WebListener; import ...
- 请问-bash-4.1$ 出现故障的原理及解决办法?
请问如下登录环境故障的原理及解决办法? [root@ ~]# su - luoahong -bash-4.1$ -bash-4.1$ 解答: [luoahong@ ~]$ rm -rf /home/l ...
- rabbitmq 相关方法
//连接$conn_args = array( 'host'=>'127.0.0.1' , 'port'=> '5672', 'login'=>'guest' , 'password ...
- MySQL中的insert ignore into, replace into等的一些用法总结
在MySQL中进行条件插入数据时,可能会用到以下语句,现小结一下.我们先建一个简单的表来作为测试: CREATE TABLE `books` ( `id` INT(11) NOT NULL AUTO_ ...
- jquery读取iframe子页面和父页面的处理
1. jquery 在iframe子页面获取父页面元素代码如下: $("#objid", parent.document) 2. jquery在父页面 获取iframe子页面的元素 ...
- 主线程MainThread与渲染线程RenderThread
在Android 5.0之前,Android应用程序的主线程同时也是一个Open GL线程.但是从Android 5.0之后,Android应用程序的Open GL线程就独立出来了,称为Render ...