Color the ball

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

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

简单的树状数组与线段树的应用。

AC代码例如以下:

普通写法!

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;int num[100005];int main()
{int n;int i,j;int a,b;while(~scanf("%d",&n)&&n){memset(num,0,sizeof num);for(i=1;i<=n;i++){scanf("%d%d",&a,&b);num[a]++;num[b+1]--;}int ans=0;for(i=1;i<=n;i++){ans+=num[i];printf("%d",ans);if(i!=n) printf(" ");}printf("\n");}return 0;
}

树状数组!

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;int c[100010];
int n,m;int lowbit(int a)
{return a&-a;
}void add(int a,int b)
{for(;a<=n;a+=lowbit(a))c[a]+=b;
}int sum(int a)
{int ans=0;for(;a>0;a-=lowbit(a))ans+=c[a];return ans;
}int main()
{int i,j;int a,b;while(scanf("%d",&n)&&n){memset(c,0,sizeof c);for(i=1;i<=n;i++){scanf("%d%d",&a,&b);add(a,1);add(b+1,-1);}int ans;for(i=1;i<=n;i++){ans=sum(i);printf("%d",ans);if(i!=n) printf(" ");}printf("\n");}return 0;
}

hdu 1556 Color the ball相关推荐

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

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

  2. HDU 1556 Color the ball (数状数组)

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

  3. 解题报告:hdu 1556 Color the ball(区间修改,单点查询)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N ...

  4. HDU 1556 Color the ball

    题解:基础的树状数组区间修改,单点查询. #include <cstdio> #include <cstring> int c[100005],a,b,n; int modif ...

  5. HDU - 1556 Color the ball(树状数组)

    N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一 ...

  6. HDOJ/HDU 1556 Color the ball(树状数组)

    Problem Description N个气球排成一排,从左到右依次编号为1,2,3-.N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动车从 ...

  7. HDU 1556 Color the Ball 线段树 题解

    本题使用线段树自然能够,由于区间的问题. 这里比較难想的就是: 1 最后更新须要查询全部叶子节点的值,故此须要使用O(nlgn)时间效率更新全部点. 2 截取区间不能有半点差错.否则答案错误. 这两点 ...

  8. hdu 1556 Color the ball 线段树 区间更新

    水一下 #include <bits/stdc++.h> #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 ...

  9. HDU 1556 Color the ball - from lanshui_Yang

    Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动 ...

最新文章

  1. 一次完整的抓包分析 Reserved TCP/IP Port List
  2. 微软称使用 Edge 而非 Chrome 能提升电池续航
  3. html 多行多列列表格,HTML跨多行跨多列表格.doc
  4. html 模板中的for循环,Flask模板引擎中的For循环
  5. linux之进程间通信--使用信号
  6. ux设计师怎样找同类产品_没有预算? 别找借口。 便宜的UX上的UX 2:让我们开始构建。...
  7. 前端React结构工程-改写render
  8. MySQL常用数据类型以及内置函数
  9. C#模板引擎NVelocity实战项目演练
  10. Log4j2 杀不死 Java
  11. Python的lambda, filter, reduce 和 map简介
  12. ubuntu前置耳机孔没声音的解决办法
  13. 【MATLAB】三角函数
  14. 计算机随机储存器是什么,随机存储器是什么
  15. grafana-普罗米修斯-监控linux-windows版
  16. 安装CAJViewer时遇到注册模块出现1904错误解决方法
  17. 微信ios上下拉网页禁止
  18. 爬取全国各地区汽车销量情况并用中国地图可视化展示
  19. 判断某键值是否存在[注册表操作]
  20. Java基础知识——Java语言基础

热门文章

  1. java编程题库下载_Java习题
  2. 第四届泉水文化论坛协调会-商协社团:平台经济谋定水产业
  3. golang-flag的问题
  4. 加固前奏2-替换application
  5. spring-data-mongodb与mongo shell的对应关系
  6. B1277 [HNOI2002]Tinux系统 树形dp
  7. 关于java和c语言中,变量重名问题
  8. 探秘小程序(9):父页面与自定义组件交互
  9. redis 持久化之 rdb 快照持久化
  10. API(Application Programming Interface,应用程序编程接口)