hdu1556——树状数组水题练习(区间更新单点求和)
来源:互联网 发布:mysql 时间戳 编辑:程序博客网 时间:2024/06/06 16:29
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1556
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 23300 Accepted Submission(s): 11320
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,输入结束。
当N = 0,输入结束。
Output
每个测试实例输出一行,包括N个整数,第I个数代表第I个气球总共被涂色的次数。
Sample Input
31 12 23 331 11 21 30
Sample Output
1 1 13 2 1
Author
8600
Source
HDU 2006-12 Programming Contest
Recommend
LL
代码:
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<algorithm>#include<vector>#include<queue>using namespace std;typedef long long ll;int c[100005];int n;int lowbit(int x){ return x&(-x);}void modify(int x,int add){ while(x>0){///更新当前点之前的BIT c[x]+=add; x-=lowbit(x); }}int sum(int x){ int ans=0; while(x<=n){ ans+=c[x]; x+=lowbit(x); } return ans;}int main(){ int i,j; int x,y; while(scanf("%d",&n),n){ memset(c,0,sizeof(c)); for(i=1;i<=n;i++){ scanf("%d %d",&x,&y); modify(y,1); modify(x-1,-1);///删掉多加的 } for(i=1;i<n;i++){ printf("%d ",sum(i)); } printf("%d\n",sum(n)); } return 0;}
区间求和和单点求和的区别,在代码上体现主要是在更新个求和两个函数的一些符号上面
阅读全文
0 0
- hdu1556——树状数组水题练习(区间更新单点求和)
- 树状数组:HDU1556 Color the ball 【区间更新,单点查询]
- hdu1556-树状数组 一维 区间更新 单点查询
- hdu1556树状数组更新区间
- hdu 1556 树状数组(区间更新,单点求和)
- 敌兵布阵------树状数组(单点更新与区间求和)
- CCF201709-5(树状数组单点更新区间求和)
- (树状数组)hdu1556 Color the ball(区间更新,单点查询)
- HDU1556 Color the ball 树状数组(区间更新单点求值)
- HDU1556——Color the ball(区间更新OR树状数组)
- hdu1166 树状数组模板:单点更新,区间求和(区间查询)
- hdoj 3874 —— 树状数组单点修改+区间求和
- scu 2057 树状数组 单点更新区间求和问题
- poj1195Mobile phones【二维树状数组。单点更新/区间求和】
- 【树状数组--单点更新区间求和】 hdu1541 Stars
- 敌兵布阵 树状数组 单点更新 区间求和
- hdu1556 color the ball 树状数组区间更新单点查询(附线段树做法)与二维扩展
- HDU1556:Color the ball(线段树区间更新单点求值)&&树状数组解法
- 思维题:UVa1334-Ancient Cipher
- 比特币源码解析(8)
- 格子刷油漆--蓝桥杯国赛历年真题
- 哈夫曼树与哈夫曼编码
- jrpofile的使用
- hdu1556——树状数组水题练习(区间更新单点求和)
- SecureCRT中文乱码问题解决方案
- ACM算法:树状数组(详细)
- C++ SOCKET通信模型(六)同步epoll
- UVA 748
- SPI总线和I2C总线的异同点
- 杜教筛如何推式子/堆柿子
- 分布式Web服务器架构分析
- Day001---普林斯顿微积分读本---java网络编程