题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1556

题目大意:

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个气球总共被涂色的次数。
 
解题思路:
裸的树状数组,但是是区间修改单点更新

 #include<iostream>
#include<algorithm>
#include<set>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = + ;
typedef long long ll;
int tree[maxn];
int n;
int lowbit(int x)
{
return x & (-x);
}
//求第x个数字
int sum(int x)
{
int ret = ;
while(x <= n)
{
ret += tree[x];
x += lowbit(x);
}
return ret;
}
//在区间[1, x]加上d
void add(int x, int d)
{
while(x > )
{
tree[x] += d;
x -= lowbit(x);
}
}
int main()
{
while(scanf("%d", &n) && n)
{
int x, y;
memset(tree, , sizeof(tree));
for(int i = ; i <= n; i++)
{
scanf("%d%d", &x, &y);
add(y, );
add(x - , -);
}
for(int i = ; i <= n; i++)
{
int x = sum(i);
printf("%d", x);
if(i == n)printf("\n");
else printf(" ");
}
}
return ;
}

hdu-1556 Color the ball---树状数组+区间修改单点查询的更多相关文章

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

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

  2. 【树状数组区间修改单点查询+分组】HDU 4267 A Simple Problem with Integers

    http://acm.hdu.edu.cn/showproblem.php?pid=4267 [思路] 树状数组的区间修改:在区间[a, b]内更新+x就在a的位置+x. 然后在b+1的位置-x 树状 ...

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

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

  4. 【树状数组区间修改单点查询】HDU 4031 Attack

    http://acm.hdu.edu.cn/showproblem.php?pid=4031 [题意] 有一个长为n的长城,进行q次操作,d为防护罩的冷却时间,Attack表示区间a-b的墙将在1秒后 ...

  5. POJ2155 Matrix(二维树状数组||区间修改单点查询)

    Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row an ...

  6. HDU 1556 Color the ball 树状数组 题解

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

  7. 【poj2155】Matrix(二维树状数组区间更新+单点查询)

    Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the ...

  8. HDU 4031 Attack(线段树/树状数组区间更新单点查询+暴力)

    Attack Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Sub ...

  9. NBOJv2 1050 Just Go(线段树/树状数组区间更新单点查询)

    Problem 1050: Just Go Time Limits:  3000 MS   Memory Limits:  65536 KB 64-bit interger IO format:  % ...

随机推荐

  1. yarn快速使用及实践建议

    什么是 yarn? 简单来说,yarn 是一个与 npm 功能相同的工具,用于前端项目的依赖管理.在使用 npm 的项目中,使用 npm 命令的地方都可以使用 yran 来代替. 为什么要使用 yar ...

  2. 2017BAPC初赛A(思维,无序图,向量)

    #include<bits/stdc++.h>using namespace std;string goods,sister[100010];int x,m;unordered_map&l ...

  3. CodeForces 116B【二分匹配】

    思路: 暴力..我不会呀.. YY一个二分匹配嘛,然后数组开小了.GG for an hour. #include <bits/stdc++.h> using namespace std; ...

  4. servlet之doPost()、doGet()

    1.doGet和doPost方法的具体应用?即在什么时候程序调用doGet方法,什么时候程序执行doPost方法? HttpServlet是从GenericServlet继承而来,因此HttpServ ...

  5. 问题:Tomcat启动产生错误严重: Error initializing endpoint java.lang.Exception

    1问题描述: Tomcat启动产生错误严重: Error initializing endpoint java.lang.Exception: Socket bind failed: [730048] ...

  6. react native 安卓生产包无法获取线上数据

    android:usesCleartextTraffic="true"

  7. jenkins相关下载链接

    Jenkins官网:https://jenkins.io/ 下载rpm安装包:   https://pkg.jenkins.io     http://mirrors.jenkins-ci.org/s ...

  8. idea中使用Git对项目进行版本控制

  9. STP-17-对抗单向链路问题

    单向链路问题是指链路上的两条传输路径中,有一条出现了问题,但并不是两条同时出现问题.这可能是因为线缆错误.切断了一条光纤线缆.拔掉了一根管线.GBIC问题,或其他问题.因为STP会监控入向BPDU,以 ...

  10. python_魔法方法(二):算术运算

    python2.2之后,对类和类型做了同意,将int().float().str().list().touple()这些BIF转换为工厂函数 >>> type(len) <cl ...