简单线段树。

 #include <stdio.h>

 #define MAXN 100005
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 int cols[MAXN<<], leaf; void PushDown(int rt) {
if ( cols[rt] ) {
cols[rt<<|] += cols[rt];
cols[rt<<] += cols[rt];
cols[rt] = ;
}
} void build(int l, int r, int rt) {
int mid;
cols[rt] = ;
if (l == r)
return ;
mid = (l+r)>>;
build(lson);
build(rson);
} void update(int ll, int rr, int l, int r, int rt) {
int mid; if (ll<=l && rr>=r) {
cols[rt]++;
return ;
}
PushDown(rt);
mid = (l+r)>>;
if (ll <= mid)
update(ll, rr, lson);
if (rr > mid)
update(ll, rr, rson);
} void query(int l, int r, int rt) {
int mid;
if (l == r) {
if (leaf)
printf(" %d", cols[rt]);
else
printf("%d", cols[rt]);
++leaf;
return ;
}
PushDown(rt);
mid = (l+r)>>;
query(lson);
query(rson);
} int main() {
int n;
int i, x, y; while (scanf("%d",&n)!=EOF && n) {
build(, n, );
for (i=; i<n; ++i) {
scanf("%d %d", &x, &y);
update(x,y,,n,);
}
leaf = ;
query(, n, );
printf("\n");
} return ;
}

【HDOJ】1556 Color the ball的更多相关文章

  1. HDOJ/HDU 1556 Color the ball(树状数组)

    Problem Description N个气球排成一排,从左到右依次编号为1,2,3-.N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动车从 ...

  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. HDU.1556 Color the ball (线段树 区间更新 单点查询)

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

  5. 【AGC025B】RGB Color

    [AGC025B]RGB Color 题面描述 Link to Atcoder Link to Luogu Takahashi has a tower which is divided into \( ...

  6. hdoj 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【差分数组裸题/模板】

    N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一 ...

  8. HDU 1556 Color the ball【算法的优化】

    /* 解题思路:每次仅仅求解一開始的第一个数字,让第一个数字加一,最后的一个数字的后面一个数减一.我们能够想想,最后加的时候,就是加上前面一个数出现的次数和自己本身出现的次数. 解题人:lingnic ...

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

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

随机推荐

  1. ASP.NET+ashx+jQuery动态添加删除表格

    aspx: <script src="../script/jquery-1.4.4.min.js" type="text/javascript" lang ...

  2. ADO简单封装(MFC)

    简单封装了一下,不是很严谨. /************************************************************************/ /* INSTRUC ...

  3. JAVA 相关资料

    在技术方面无论我们怎么学习,总感觉需要提升自已不知道自己处于什么水平了.但如果有清晰的指示图供参考还是非常不错的,这样我们清楚的知道我们大概处于那个阶段和水平. Java程序员 高级特性 反射.泛型. ...

  4. EL标签和JSTL标签---JSP页面的应用

    ====EL(Expression Language)表达式语言:用于计算和输出存储在标志位置(page.request.session.application)的java对象的值: 1.开启和关闭E ...

  5. 数据库(学习整理)----3--Oracle创建表和设置约束

    BBS论坛表设计 包含的表:BBSusers(用户表),BBSsection(版块表),BBStopic(主贴表),BBSreply(跟帖表) 表结构 1)BBSusers 字段名 字段说明 数据类型 ...

  6. 配置hive元数据库mysql时候出现 Unable to find the JDBC database jar on host : master

    解决办法: cd /usr/share/java/,(没有java文件夹,自行创建)rz  mysql-connector-java-***.jar,mv mysql-connector-java-* ...

  7. 237. Delete Node in a Linked List(C++)

    237. Delete Node in a Linked Lis t Write a function to delete a node (except the tail) in a singly l ...

  8. php中如何实现网上商城用户历史浏览记录的代码

    /如是COOKIE 里面不为空,则往里面增加一个商品ID if (!empty($_COOKIE['SHOP']['history'])){ //取得COOKIE里面的值,并用逗号把它切割成一个数组 ...

  9. 图解数据结构树之AVL树

    AVL树(平衡二叉树): AVL树本质上是一颗二叉查找树,但是它又具有以下特点:它是一棵空树或它的左右两个子树的高度差的绝对值不超过1,并且左右两个子树都是一棵平衡二叉树.在AVL树中任何节点的两个子 ...

  10. MVVM模式应用 之为ApplicationBarIconButton 添加Command操作属性

    在学习MVVM的过程中,总是会遇到挫折,一碰到就是花费好长时间去解决..唉,不求量,只求质. 第一种(已经实践成功): (1)http://bindableapplicationb.codeplex. ...