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. 转载:Ununtu下中文乱码解决方案

    转载: 添加中文字符编码: $sudo vim /var/lib/locales/supported.d/local #添加下面的中文字符集 zh_CN.GBK GBK zh_CN.GB2312 GB ...

  2. continuous integration and continuous deployment in DW/BI

    deployment methodIn Redshift1, Deploy process: Drop and Refresh the view, Drop table, Create an empt ...

  3. 谈一下spring 的理解

    spring,大家基本都在使用,两个核心: 声明式事务AOP : 控制反转依赖注入IOC: 以前对控制反转和依赖注入很模糊,现在大概理解了意思,控制反转,有spring容易来控制bean 的创建,我们 ...

  4. EditText 密码属性

    <EditText android:id="@+id/et_password" android:layout_width="match_parent" a ...

  5. 【转】Android开发中的SQLite事务处理,即beginTransaction()方法

    使用SQLiteDatabase的beginTransaction()方法可以开启一个事务,程序执行到endTransaction() 方法时会检查事务的标志是否为成功,如果程序执行到endTrans ...

  6. pat 1062. Talent and Virtue (25)

    难得的一次ac 题目意思直接,方法就是对virtue talent得分进行判断其归属类型,用0 1 2 3 4 表示 不合格 sage noblemen foolmen foolmen 再对序列进行排 ...

  7. JavaScript和prototype

    Protoype这个词在javascript中可以有两种理解: 第一种是作为javascript中的一个属性,其一般出现的形式为:类名.prototype. prototype 属性让你有能力向对象添 ...

  8. java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.L(转)

    09-09 10:19:59.979: E/AndroidRuntime(2767): FATAL EXCEPTION: main09-09 10:19:59.979: E/AndroidRuntim ...

  9. 【转】Java 读写Properties配置文件

    [转]Java 读写Properties配置文件 1.Properties类与Properties配置文件 Properties类继承自Hashtable类并且实现了Map接口,也是使用一种键值对的形 ...

  10. (转)PHP文件没有结尾的?>有什么好处?

    1.PHP文件没有结尾的?>有什么好处?-- 防止输出一些不必要的空行或者空格2. 如果你是php和html混编的话结尾?> 还是有必要的,否则会报错. 如果没有?>文件末尾的空白行 ...