hdu1556:http://acm.hdu.edu.cn/showproblem.php?pid=1556

题意:中文题。

题解:这一题当然可以直接用线段树来打,但是最近在学树状数组,所以用树状数组打了。树状数组有两种更新和求和的方式。1是向上更新,向下查询。2是向下更新,向上查询。第二种可以用来区间更新。例如更新(u,v,num),先update(v,num),然后update(u-1,-num);getsum(i)得到的就是第i个数的值。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 1000000
using namespace std;
int c[MAXN];
int n,u,v;;
int lowbit(int x){
return x&(-x);
}
void add(int x,int num){
while(x>=){
c[x]+=num;
x-=lowbit(x);
}
}
int getsum(int x){
int sum=;
while(x<=n){
sum+=c[x];
x+=lowbit(x);
}
return sum;
}
int main(){
while(~scanf("%d",&n)&&n){
memset(c,,sizeof(c));
for(int i=;i<=n;i++){
scanf("%d%d",&u,&v);
add(v,);
add(u-,-);
}
for(int i=;i<n;i++)
printf("%d ",getsum(i));
printf("%d\n",getsum(n));
}
}

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 ...

  10. Color the ball(树状数组+线段树+二分)

    Color the ball Time Limit : 9000/3000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tota ...

随机推荐

  1. Invocation of init method failed; nested exception is org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.cache.impl

    严重: Exception sending context initialized event to listener instance of class org.springframework.we ...

  2. Android使用Linux mount获取SdCard存储文件夹

    Android的智能手机各不同样.如今非常多Android智能手机都是自带存储,有的还带有扩展内存的Sdcard卡槽. 在Android开发中,非常多时候依据Android提供的获取SdCard存储方 ...

  3. mac下使用brew安装svn javahl的问题

    eclipse老提示javahl太久必须得1.8以上,以前不知道什么时候在/usr/bin装过1.7的svn. 1. 删除1.7的svn sudo rm /usr/bin/svn 2.使用brew安装 ...

  4. JFreeChart当鼠标停留在热点提示自定义信息功能

    当鼠标停留在数据点时,希望有提示信息显示,但是根据业务需要,我们需要自定义显示一下信息!具体功能实现如下: 首先我们要弄明白,Jfreechart鼠标提示信息显示主要是得到一个数据的map对象,该ma ...

  5. chrome浏览的下载扩展程序

    C:\Users\XXXX\AppData\Local\Google\Chrome\User Data\Default\Extensions 地址栏输入chrome://extensions/并回车打 ...

  6. window.applicationCache事件,介绍

    1.关于applicationCache对象 在IE和Google中 为ApplicationCache对象 而在FF中为 OfflineResourceList对象 通过ApplicationCac ...

  7. Js数学函数1

    1.取模求余数 //1.JS取模求余 //输出 for (var i = 0; i < 20; i++) { if (i % 3 == 0) { documentHelper.WriteText ...

  8. break、continue和goto 三者作用介绍

    跳跃语句 由于break.continue和goto语句有助于跳跃到代码中的某个特定语句,因此它们属于跳跃语句.下面是这三个语句的介绍. ①break语句 这个语句常与switch语句联合使用:但是, ...

  9. C# Double类型 不四舍五入

    测试中发现Double类型需要#0.00 小数点精度为后2位,并且多余部分不需要四舍五入,直接截断 用字符串处理也可以,但是比较麻烦 这里给出一种思路: double a = 9999.999; a ...

  10. 156 Useful Run Commands

    To Access… Run Command Accessibility Controls access.cpl Accessibility Wizard accwiz Add Hardware Wi ...