Color the ball

Time Limit: 3000 MS Memory Limit: 32768 KB

64-bit integer IO format: %I64d , %I64u Java class name: Main

[Submit] [Status] [Discuss]

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
#include <iostream>
#include <string.h>
#include <stdio.h> using namespace std;
#define max 100005
int c[max];
int n; int lowbit(int x)
{
return x&-x;
} void update(int i,int val)
{
while(i>)
{
c[i]+=val;
i-=lowbit(i);
}
} int get_sum(int i)
{
int s=;
while(i<=n)
{
s+=c[i]; ///上下两行 不可换位置~~~~~
i+=lowbit(i);
}
return s;
} int main()
{ while(scanf("%d",&n),n)
{
int x,y;
memset(c,,sizeof(c));
for(int i=; i<n; i++)
{ scanf("%d%d",&x,&y);
update(y,);
update(x-,-);
}
for(int i=; i<n; i++) ///注意脚标
printf("%d ",get_sum(i));
printf("%d\n",get_sum(n));
}
return ;
}

HDU 1556 区间查询的更多相关文章

  1. HDU 1556 线段树或树状数组,插段求点

    1.HDU 1556  Color the ball   区间更新,单点查询 2.题意:n个气球,每次给(a,b)区间的气球涂一次色,问最后每个气球各涂了几次. (1)树状数组 总结:树状数组是一个查 ...

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

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

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

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

  4. hdu 1556 A - Color the ball 数状数组做法

    #include<bits/stdc++.h> using namespace std; ; int n; int c[maxn]; int lowbit(int x) { return ...

  5. HDU.1556 Color the ball (线段树 区间更新 单点查询)

    HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...

  6. hdu 1556 Color the ball 线段树

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

  7. hdu 1556.Color the ball 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 题目意思:有 n 个气球从左到右排成一排,编号依次为1,2,3,...,n.给出 n 对 a, ...

  8. hdu 1556 Color the ball(树状数组)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 题意:N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数[a,b]之间的气球 ...

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

    http://acm.hdu.edu.cn/showproblem.php?pid=1556 题意: N个气球,每次[a,b]之间的气球涂一次色,统计每个气球涂色的次数. 思路: 这道题目用树状数组和 ...

随机推荐

  1. APP强制退出

    第一种方法: 企业版可以用,Appstore可能被拒,慎用 - (void)exitApplication { AppDelegate *app = [UIApplication sharedAppl ...

  2. 网页启用Gzip压缩 提高浏览速度

    启用Gzip压缩的好处 它的好处显而易见,提高网页浏览速度,无论是之前说的精简代码.压缩图片都不如启用Gzip来的实在.下图为启用Gzip后的效果. Gzip压缩效率非常高,通常可以达到70%的压缩率 ...

  3. [Hbase]Hbase技术方案

    HBase架构简介 HBase在完全分布式环境下,由Master进程负责管理RegionServers集群的负载均衡以及资源分配,ZooKeeper负责集群元数据的维护并且监控集群的状态以防止单点故障 ...

  4. 使用mysql proxy对数据库进行读写分离

    服务器安排如下: 192.168.100.128 主 192.168.100.129 从 192.168.100.130 mysql-proxy 1.在100.130中下载安装mysql-proxy ...

  5. win32 注册表操作

    创建键 RegCreateKeyEx int SetRecordVideoSavedDays(int newSavedDays) { HKEY hSubKey = NULL; LONG lRet = ...

  6. velocity 框架

    Java模板引擎 Velocity是一个基于java的模板引擎(template engine).它允许任何人仅仅使用简单的模板语言(template language)来引用由java代码定义的对象 ...

  7. Linux运维之shell脚本

    一.bash漏洞 1)bash漏洞 bash漏洞是控制Linux计算机命令提示符的软件中存在的漏洞. bash是一个为GNU计划编写的Unix shell.它的名字是一系列缩写:Bourne-Agai ...

  8. Bubble(冒泡排序)————Java

    用Java进行冒泡排序的代码,利用一个flag进行优化算法: import java.util.Scanner; public class Bubble_Sort { private static i ...

  9. android 自动更新

    http://blog.csdn.net/zml_2015/article/details/50756703

  10. mongodb知识积累

    1: 安装mongodb https://www.cnblogs.com/zhangdaicong/p/7492494.html 2:配置文件 vi /etc/mongodb.conf https:/ ...