题目链接: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. CSS设计指南之理解盒子模型

    原文:CSS设计指南之理解盒子模型 一.理解盒模型 每一个元素都会在页面上生成一个盒子.因此,HTML页面实际上是由一堆盒子组成的.默认情况下,每个盒子的边框不可见,背景也是透明的,所以我们不能直接看 ...

  2. TabHost+RadioGroup搭建基础布局

    xml的形势如下: <tabhost> <linearlayout vertival> <framlayout weight=1/> <tabwidget g ...

  3. [ACM] POJ 3686 The Windy&#39;s (二分图最小权匹配,KM算法,特殊建图)

    The Windy's Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 4158   Accepted: 1777 Descr ...

  4. SDUT 2894-C(最短spfa)

    C Time Limit: 7000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述 给出一个带权无向图.包括n个点,m条边.求出s,e的最短路.保证最短路存在 ...

  5. 它们的定义dialog

    (1)你需要准备自己的自定义对话框样式,是一个布局文件 <?xml version="1.0" encoding="utf-8"? > <Li ...

  6. JAVA基础实例(三)--排序

    冒泡排序 是一种简单的排序算法.它反复地走訪过要排序的数列,一次比較两个元素.假设他们的顺序错误就把他们交换过来.走訪数列的工作是反复地进行直到没有再须要交换,也就是说该数列已经排序完毕. 这个算法的 ...

  7. bootstrap+jQuery.validate

    bootstrap+jQuery.validate表单校验   谈谈表单校验 这大概是一种惯例,学习前台后台最开始接触的业务都是用户注册和登录.现在社会坚持以人为本的理念,在网站开发过程同样如此.Us ...

  8. Java里泛型有什么作用

    1 泛型赋予了类型參数式多态的能力 2 泛型的第一个优点是编译时的严格类型检查,提高了程序的安全性和健壮性,这是集合框架最重要的特点. 3 泛型消除了绝大多数的类型转换.假设没有泛型,当你使用集合框架 ...

  9. vim cheat sheet

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzE1Mjg5NQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  10. .NET反编译之Reflector

    .NET反编译之Reflector 这几日由于公司需要, 看了些.NET反编译技巧,特地和大家分享下 .NET反编译工具很多,Reflector是其中一个很优秀的工具,所以就用它来进行反编译工作了.今 ...