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. postfix 设置邮件头翻译,本域邮件不进行邮件头翻译,仅发送至外网的进行邮件头翻译?

    postfix 设置邮件头翻译,本域邮件不进行邮件头翻译,仅发送至外网的进行邮件头翻译? 现在设置的 smtp_generic_maps = hash:/etc/postfix/generic sen ...

  2. ubuntu如何实现双屏显示

    转载自https://blog.csdn.net/tianmaxingkong_/article/details/50570538

  3. b2c项目访问

    http://xmpw.testbase.smi170.com:8091/member/movie_coupon_new.php

  4. Ubutun 配置php redis 扩展

    1.安装redis 下载:wget --no-check-certificate https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz ...

  5. java struts2 的 文件下载

    jsp: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnco ...

  6. canvas绘图实现浏览器等待效果

    一:创建画布 <canvas width="600" height="600" id="canvas" style="bor ...

  7. web-Amazon

    一 准备实验数据 1.1.下载数据 wget http://snap.stanford.edu/data/amazon/all.txt.gz 1.2.数据分析 1.2.1.数据格式 product/p ...

  8. JavaScript 模拟键盘事件和鼠标事件(比如模拟按下回车等)

    http://blog.csdn.net/lovelyelfpop/article/details/52471878# 封装好的function大概就是这样: function fireKeyEven ...

  9. HTTP 错误 404.17 - Not Found和 HTTP 错误 404.2 - Not Found 解决办法

    HTTP 404.2 - Not Found" IIS 7.5 请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理 解决办法: 使用aspnet_regiis.exe注册.NET Fr ...

  10. How to temporally disable IDE tools (load manually)

    It is possible to prevent the IDE Tools from being loaded automatically when starting Visual Studio. ...