题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556

树状数组的  update的应用,逆序更新

代码:

 #include <stdio.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <iostream>
#include <ctype.h>
#include <iomanip>
#include <queue>
#include <map>
#include <stdlib.h>
using namespace std; int c[],n; int lowbit(int x)
{
return x&(-x);
} void update(int x,int y)
{
while(x>){
c[x]=c[x]+y;
x=x-lowbit(x);
}
} int sum(int x)
{
int r=;
while(x<=n){
r+=c[x];
x+=lowbit(x);
}
return r;
} int main()
{
int a,b;
while(~scanf("%d",&n)&&n!=){
memset(c,,sizeof(c));
for(int i=;i<=n;i++){
scanf("%d%d",&a,&b);
update(b,);
update(a-,-);
}
for(int i=;i<n;i++){
printf("%d ",sum(i));
}
printf("%d\n",sum(n));
}
}

hdu 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 1199 Color the Ball

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

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

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

  6. 线段树(求单结点) hdu 1556 Color the ball

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

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

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

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

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

  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. 数据结构之计算器的实现(JAVA)(四)

    原理: 1.将中序表达式变化兴许表达式 2.当前字符为数字,将该数字放入栈中 3.当前字符为操作符,从栈中取出两个树,依据操作符来运算,将运算结果放入到栈中 4.反复,直到将字符操作完.此时栈中仅仅剩 ...

  2. 乐在其中设计模式(C#) - 策略模式(Strategy Pattern)

    原文:乐在其中设计模式(C#) - 策略模式(Strategy Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 策略模式(Strategy Pattern) 作者:webabc ...

  3. 使用Simple DNS plus 构建自己的DNS

    1.下载并安装Simple DNS plus 2.界面例如以下: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2tfYm9zcw==/font/5a6L ...

  4. hibernate它 10.many2many单向

    在前文hibernate之5.many2one单向提到多对多关系,表结构设计是基于中间表来实现, 以下以用户与角色(多对多)为例,在Hibernate是怎样操作的 表结构设计: 类图: CRUD; S ...

  5. 高榕资本宾悦:未使用的企业家Testin云测试服务类故障

    高榕资本岳斌:创业者未使用Testin云測试服务属不合格 2014/10/09 · Testin · 开发人员訪谈 Testin云測与工信部等联合承办的ICT中国.2014高层论坛之移动开发人员分论坛 ...

  6. 1.cocos2dx 3.2环境结构

    1        所需软件 jdk-7u25-windows-i586.exe python-2.7.8.amd64.msi cocos2d-x-3.2.zip apache-ant-1.9.4.zi ...

  7. [Android 4.4.4] 泛泰A870 通过刷第三版 Mokee4.4.4 KTU84P 20140626 RC2.1 by syhost

    主题及注意事项请访问以前的版本: http://blog.csdn.net/syhost/article/details/29931291 此RC2.1版比RC2.0改进的地方: 1. Mokee本身 ...

  8. Java常见Exception物种

    Java常见Exception物种 1.ClassNotFoundException 2.IOException 3.NoSuchFieldException 4.NoSuchMethodExcept ...

  9. BZOJ1579 USACO 2009 Feb Gold 3.Revamping Trails Solution

    标题效果:一个N积分m无向图边.它可以是路径k右边缘值变0,确定此时1-n最短路径长度. Sol:我以为我们考虑分层图,图复制k+1部分,每间0~k一层.代表在这个时候已经过去"自由边缘&q ...

  10. oracle record is locked by another user

    这个问题的根源先说说:午后更改数据库表,保存更改后,却没有提交完整.突然,去什么地方调试,拔掉网线,然后插上网线,这个出现record is locked by another user错误.网上找原 ...