Color the ball

Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7497    Accepted Submission(s): 3865

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
 
Author
8600
 
Source
 
简单的树状数组。
依旧树状数组的原理,如果直接采用ope(a,b),显然会超时,而且若是在树状数组中划定界限来统计,图画的个数,这样这样明显是统计不到的,
我们知道,树状数组是一个向上修改的的过程,然后向下统计求sum , 若果我们要夹出这个数值,那么我们必须要进行两次的修改,来最终确定有多少
 
代码:
 #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define maxn 100000
int aa[maxn+];
int nn;
int lowbit(int x)
{
return x&(-x);
}
void ope(int x,int val)
{
while(x<=nn)
{
aa[x]+=val;
x+=lowbit(x);
}
}
int sum(int x)
{
int ans=;
while(x>)
{
ans+=aa[x];
x-=lowbit(x);
}
return ans;
}
int main()
{
int i,a,b;
while(scanf("%d",&nn),nn)
{
memset(aa,,sizeof(aa));
for(i=;i<nn;i++)
{
scanf("%d%d",&a,&b);
ope(a,);
ope(b+,-);
}
printf("%d",sum());
for(i=;i<=nn;i++)
printf(" %d",sum(i));
putchar();
}
return ;
}

HDUOJ -----Color the ball的更多相关文章

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

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

  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. Color the Ball[HDU1199]

    Color the Ball Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  5. 线段树--Color the ball(多次染色问题)

    K - Color the ball Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  6. hdu 1199 Color the Ball

    http://acm.hdu.edu.cn/showproblem.php?pid=1199 Color the Ball Time Limit: 2000/1000 MS (Java/Others) ...

  7. Color the ball HDOJ--1556

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

  8. hdoj 1556 Color the ball【线段树区间更新】

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

  9. hdu 1199 Color the Ball(离散化线段树)

    Color the Ball Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

随机推荐

  1. 解决sqlite删除数据或者表后,文件大小不变的问题

    原因分析: sqlite采用的是变长纪录存储,当你从Sqlite删除数据后,未使用的磁盘空间被添加到一个内在的"空闲列表"中用于存储你下次插入的数据,用于提高效率,磁盘空间并没有丢 ...

  2. Kmeans聚类算法分析(转帖)

    原帖地址:http://www.opencvchina.com/thread-749-1-1.html       k-means是一种聚类算法,这种算法是依赖于点的邻域来决定哪些点应该分在一个组中. ...

  3. 我所理解的设计模式(C++实现)——解释器模式(Interpreter Pattern)

    概述: 未来机器智能化已然成为趋势,现在手机都能听懂英语和普通话,那我大中华几万种方言的被智能化也许也是趋势,我们的方言虽然和普通话相似,但是还是不一样的.这可能需要一个新的语法分析器来帮助我们. 我 ...

  4. 如何查看ETW Trace?

    三种方法: LogParser Tractrpt - C:\Windows\System32 SvcTraceViewer.exe   后面的链接中有使用的详细步骤.   参考资料 ========= ...

  5. Candy leetcode java

    题目: There are N children standing in a line. Each child is assigned a rating value. You are giving c ...

  6. Longest Common Prefix leetcode java

    题目: Write a function to find the longest common prefix string amongst an array of strings. 题解: 解题思路是 ...

  7. Bootstrap学习js插件篇之滚动监听

    1.滚动监听 案例 滚动监听插件可以根据滚动条的位置自动更新所对应的导航标记.Bootstrap中文网左侧就是一个滚动监听的例子. 代码段: <nav id="navbar-examp ...

  8. BZOJ 3732 Network Link-Cut-Tree (我是认真的!!

    题目大意:给定一个n个点m条边的无向连通图.k次询问两点之间全部路径中最长边的最小值 LCT的裸题! 首先维护一个动态的最小生成树,然后每次增加边时删除两点间路径上权值最大的边.最后询问时直接求x到y ...

  9. JVM总结-内存监视手段及各区域内存溢出解决

    转载:https://blog.csdn.net/xuqu_volition/article/details/53786096 引言 本文仅关注一些常见的虚拟机内存监视手段,以及JVM运行时数据区各个 ...

  10. APP 打包測试流程 从零開始

    前言: 苹果应用打包測试一直是件令人头疼的事.尤其是第一次打包的时候,因为苹果官网是全英文性且缺少仔细的步骤指引.刚開始学习的人往往要花费非常多时间去干一件三分钟就能搞定的事. 今天我们来透彻的解说一 ...