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
 
#include<bits/stdc++.h>

using namespace std;
int lowbit(int x)
{
return x&(-x);
}
int n;
const int N=1e5+;
int s[N];
void updata(int x,int y)
{
for(int i=x;i<=n;i+=lowbit(i)){
s[i]+=y;
}
} int sum(int x)
{
int ans=;
for(int i=x;i>;i-=lowbit(i)){
ans+=s[i];
}
return ans;
}
int main()
{
while(scanf("%d",&n)==,n){
memset(s,,sizeof(s));
for(int i=;i<n;i++){
int a,b;
scanf("%d %d",&a,&b);
updata(a,);
updata(b+,-);
}
for(int i=;i<=n;i++){
if(i!=) printf(" ");
printf("%d",sum(i));
}
printf("\n");
}
return ;
}
 

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)To ...

  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 (线段树 区间更新 单点查询)

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

  4. hdu 1556 Color the ball(区间更新,单点求值)

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

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

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

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

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

  7. hdu 1556 Color the ball(线段树区间维护+单点求值)

    传送门:Color the ball Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/3276 ...

  8. HDU 1556 Color the ball (一维树状数组,区间更新,单点查询)

    中文题,题意就不说了 一开始接触树状数组时,只知道“单点更新,区间求和”的功能,没想到还有“区间更新,单点查询”的作用. 树状数组有两种用途(以一维树状数组举例): 1.单点更新,区间查询(即求和) ...

  9. HDU 1556 Color the ball (树状数组区间更新)

    水题,练习一下树状数组实现区间更新. 对于每个区间,区间左端点+1,右端点的后一位-1,查询每个位置的覆盖次数 #include <cstdio> #include <cstring ...

随机推荐

  1. Dapper.net ORM

    参考链接:https://github.com/StackExchange/dapper-dot-net Dapper - a simple object mapper for .Net Dapper ...

  2. 工具类(为控件设置圆角) - iOS

    为了便于日常开发效率,因此创建了一些小的工具类便于使用.具体 code 如下:声明: /* 为控件添加边框样式_工具类 */ #import <UIKit/UIKit.h> typedef ...

  3. Angularjs基础(六)

    AngularJS HTML DOM AngularJS为HTML DOM 元素的属性提供了绑定应用数据的指令. ng-disabled指令 ng-disabled指令直接绑定应用数据到HTML的di ...

  4. Keepalived搭建主从架构、主主架构实例

    实例拓扑图: DR1和DR2部署Keepalived和lvs作主从架构或主主架构,RS1和RS2部署nginx搭建web站点. 注意:各节点的时间需要同步(ntpdate ntp1.aliyun.co ...

  5. 【c学习-8】

    /*继承结构体*/ #include // 定义子结构体 struct date{ int year; int month; int day; }; //定义父结构体 struct student{ ...

  6. ethereum(以太坊)(基础)--容易忽略的坑(一)

    pragma solidity ^0.4.0; contract base{ address public _owner=msg.sender; uint _a; string internal _b ...

  7. scala成长之路(1)基本语法和数据类型

    scala作为JVM上的Lisp,是一种geek类型的编程语言,也一直是我等java程序员眼中的梦寐以求的一门技能,遂下定决心花一段时间好好学习scala.第一天学习,主要介绍与java在编程上的主要 ...

  8. python查询mysql数据

    >>>cur.execute("select * from 表名") >>>lines=cur.fetchall() >>>f ...

  9. linux安装python并安装pip

    因为最近要在linux环境下进行python编程,所以就试着去安装了一下,但是网上关于python以及pip的安装说实话有点混乱,所以我今天就把前辈的经验再次总结一下,希望可以给大家提供帮助. pyt ...

  10. python-time模块、sys模块、os模块以及大量实例

    模块 通俗的说模块就把一个已经写好的带有可使用的函数的文件,通过文件名进行导入,然后调用里面的函数等来完成所需功能,模块封装了你需要实现功能的代码,使用者只需调用即可,简化代码量,缩短编程时间. ti ...