Color the ball

Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6787    Accepted Submission(s): 3549

Problem Description
N
个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <=
b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色。但是N次以后lele已经忘记了第I个气球已经涂过几次颜
色了,你能帮他算出每个气球被涂过几次颜色吗?
 
Input
每个测试实例第一行为一个整数N,(N <= 100000).接下来的N行,每行包括2个整数a b(1 <= a <= b <= N)。
当N = 0,输入结束。
 
Output
每个测试实例输出一行,包括N个整数,第I个数代表第I个气球总共被涂色的次数。
 
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
 
 
Author
8600
 

代码:

 /*@coder龚细军*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define maxn 100004
int ss[maxn],n;
int lowbit(int x)
{
return x&(-x);
}
void ope(int a,int b)
{
while(a<=n)
{
ss[a]++;
a+=lowbit(a);
}
b++; //因为b这个位置,也在a~b内,所以要上一位..
while(b<=n)
{
ss[b]--;
b+=lowbit(b);
}
//这样 这统计了a+b段,相当于{a,n}-{b,n}=={a,b}
}
int sum(int a)
{
int ans=;
while(a>)
{
ans+=ss[a];
a-=lowbit(a);
}
return ans;
}
int main()
{
int a,b,i;
while(scanf("%d",&n),n)
{
memset(ss,,sizeof(int)*(n+));
for(i=;i<n;i++)
{
scanf("%d %d",&a,&b);
ope(a,b);
}
for(i=;i<n;i++)
{
printf("%d ",sum(i));
}
printf("%d\n",sum(n));
}
return ;
}

HDUOJ-----1556Color the ball的更多相关文章

  1. HDUOJ -----Color the ball

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  2. AOJ 0033 Ball【DFS】

    有一个筒,从A口可以放球,放进去的球可通过挡板DE使其掉进B管或C管里,现有带1-10标号的球按给定顺序从A口放入,问是否有一种控制挡板的策略可以使B管和C管中的球从下往上标号递增. 输入: 第一行输 ...

  3. hduoj 1455 && uva 243 E - Sticks

    http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...

  4. var ball0=new Ball("executing") 是怎样被执行的?

    function Ball(message){ alert(message); }; var ball0=new Ball("executing"); //var ball0=ne ...

  5. blue and red ball

    #include<iostream> #include<cstring> using namespace std; int sum; ]; int n; int head; i ...

  6. HDU 1556 Color the ball(线段树区间更新)

    Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...

  7. HD1556Color the ball(树状数组)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  8. hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  9. hdu 1556:Color the ball(线段树,区间更新,经典题)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  10. hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...

随机推荐

  1. Eclipse 搭建struts2 spring3 hibernate3环境实战 待完善

    1.struts2 目前是2.3版本,下载地址http://struts.apache.org/download.cgi struts2包 struts2-core-2.3.16.3.jar stru ...

  2. Nginx缓存使用官方教程及常见问题解答

    原文地址:http://www.kuqin.com/shuoit/20150804/347388.html 我们都知道,应用程序和网站一样,其性能关乎生存.但如何使你的应用程序或者网站性能更好,并没有 ...

  3. 数据库实例: STOREBOOK > 表空间 > 编辑 表空间: TEMP

    ylbtech-Oracle:数据库实例: STOREBOOK  >  表空间  >  编辑 表空间: TEMP 表空间  >  编辑 表空间: TEMP 1. 一般信息返回顶部 1 ...

  4. OpenCV学习(34) 点到轮廓的距离

    在OpenCV中,可以很方便的计算一个像素点到轮廓的距离,计算距离的函数为: double pointPolygonTest(InputArray contour, Point2f pt, bool ...

  5. DP 换硬币问题

    设有n种不同面值的硬币,现要用这些面值的硬币来找开待凑钱数m,可以使用的各种面值的硬币个数不限.    找出最少需要的硬币个数,并输出其币值. package DP; import java.util ...

  6. Singleton 单例模式 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  7. 【软引用】弱引用 图片的加载与缓存 OOM

    在java.lang.ref包中提供了几个类:SoftReference类.WeakReference类和PhantomReference类,它们分别代表软引用.弱引用和虚引用. ReferenceQ ...

  8. JAVASCRIPT校验大全[转]

    var IsFireFox = document.getElementById &&! document.all;//判断是否为FireFox //页面里回车到下一控件的焦点 func ...

  9. ECMAScript5之Object学习笔记(一)

    随着IE的逐步追赶,目前到IE11已经能够很好的支持ECMAScript5标准了,其他的现代浏览器像firefox,chrome,opera就更不用说了. 再加上nodejs使得javascript在 ...

  10. json字符串和dict互转

    json字符串和dict互转 import json str = '{"params":[{"id":222,"offset":0},{&q ...