Color the ball(杭电1556)
Color the ball
Time Limit : 9000/3000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 8 Accepted Submission(s) : 2
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
当N = 0,输入结束。
Output
Sample Input
3
1 1
2 2
3 3
3
1 1
1 2
1 3
0
Sample Output
1 1 1
3 2 1
/*树状数组应用。 */
#include<stdio.h>
#include<string.h>
int n,tree[100010];
int lowbit(int N)
{
return N&(-N);
}
int add(int i,int t)//求第i个数之后都加上t.
{
while(i<=n)
{
tree[i]+=t;
i+=lowbit(i);
}
}
int sum(int m)
{
int sum=0;
while(m>0)
{
sum+=tree[m];
m-=lowbit(m);
}
return sum;
}
int main()
{
int i,a,b;
while(scanf("%d",&n),n)
{
memset(tree,0,sizeof(tree));
for(i=0;i<n;i++)
{
scanf("%d %d",&a,&b);
add(a,1); //将a之后的涂色次数加1.
add(b+1,-1);//将b之后的涂色次数减1.
}
printf("%d",sum(1));
for(i=2;i<=n;i++)
printf(" %d",sum(i));
printf("\n");
}
return 0;
}
Color the ball(杭电1556)的更多相关文章
- hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1556:Color the ball(线段树,区间更新,经典题)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- HDU 1556 Color the ball(线段树区间更新)
Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...
- hdoj 1556 Color the ball【线段树区间更新】
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 1556 Color the ball (数状数组)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1556 Color the ball (线段树+代码详解)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu 1556 Color the ball(线段树区间维护+单点求值)
传送门:Color the ball Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/3276 ...
- HDU 1556 Color the ball 前缀和+思维
Color the ball N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球 ...
随机推荐
- 读书笔记-Java设计模式
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! Java的封装性很好,拿访问控制符来讲,没有权限的类或方法是不能访问的.如public,都可访问:p ...
- 4.Windows下安装ZooKeeper
转自:https://www.cnblogs.com/mstmdev/p/5612791.html 官方主页: https://zookeeper.apache.org/ 选择合适的镜像地址下 ...
- 【2017 Multi-University Training Contest - Team 10】Schedule
[链接]http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1010&cid=767 [题意] 给一些区间,每台机器在这些区间 ...
- 你真得懂Javascript中的==等于运算符吗?
var i = 2; Number.prototype.valueOf = function() { return i++; }; var a = new Number( 42 ); if (a == ...
- nginx源代码分析--事件模块 & 琐碎
通过HUP信息使得NGINX实现又一次读取配置文件,使用USR2信号使得NGINX实现平滑升级. 在nginx中有模块这么一说,对外全部的模块都是ngx_module_t类型,这个结构体作为全部模块的 ...
- python3 求斐波那契数列(Fibonacci sequence)
输出斐波那契数列的前多少个数. 利用函数 #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan # ----斐波那契数列( ...
- 2015,我的投资理财策略(股权众筹+P2P网贷+活期理财)
纸币流行,尤其是当今中国的市场经济,纸币几乎是一直是贬值的,每个人的财富都在被不断地稀释,可能是被政府.如果你不注意保值增值,你就越来越穷. 当年的万元户,在今天看来就是一个笑话,其实不怎么好 ...
- SOAP消息结构
邵盛松 2012-5-22 一 SOAP消息结构 SOAP消息包括以下元素 必需的 Envelope 元素,可把此 XML 文档标识为一条 SOAP 消息,XML文件的顶层元素,代表该文件为SOAP消 ...
- linux中关闭程序或进程
- ARCGIS动态画点
小马哥淡定 原文 ARCGIS动态画点 private void DrawPointOnMap(double x, double y,bool clear) { IMapControl2 pMapCt ...