简单线段树。

 #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. Bash中的$符号

    脚本名称:$0 PID:$$ 参数个数:$# 脚本返回值:$? 第x个参数:$x 第10个以上的参数加大括号:${10} 所有参数:$@ #!/bin/bash echo "The prog ...

  2. Jquery Call WebDav

    最近研究了一下WebDav,尝试了一下用Jquery.ajax 发生请求访问WebDav. 代码如下: <!DOCTYPE html> <html xmlns="http: ...

  3. 造一个Badge Service(徽章)的轮子

    什么是Badge Service 细心的读者朋友一定在很多Github的Repo,npm的package页面看到过诸如 的徽章.这些徽章是干什么用的? 大家看到上文中我引用的Badge的左侧,是Dow ...

  4. angularjs中异常处理

    1.TypeError: Cannot read property '$valid' of undefined a. Add ng-submit attribute to the form: < ...

  5. matlab中find 函数如何使用

    find函数用于返回所需要元素的所在位置 (位置的判定:在矩阵中,第一列开始,自上而下,依次为1,2,3...,然后再从第二列,第三列依次往后数) 举例: ①find(A)返回矩阵A中非零元素所在位置 ...

  6. java_反射_及其简单应用(2016-11-16)

    话不多说直接上代码 接口: package bean; /** * user接口 */ public interface User { public String getName(); public ...

  7. IE6 兼容问题总结

    1 IE6,IE7下设置body{overflow:hidden;}失效Bug

  8. cocos2dx 实现不一样的ScrollView

    原来在公司被迫加班加点赶工,用lua实现的版本:http://www.cnblogs.com/mmc1206x/p/4146911.html 后来因我个人的需要, 用C++实现了一个版本. 蓦然回首, ...

  9. Frameset布局

    <FRAMESET> <FRAME> <NOFRAMES> <IFRAME> ■ 框架概念 : 所谓框架便是网页画面分成几个框窗,同时取得多个 URL. ...

  10. 网络基础---OSI 模型与TCP/IP

    一.网络的演进: 1.简单的联接:1960's ------------ 1970's    Host Network 六十至七十年代,网络的概念主要是主机架构的低速串行联接,提供应用程序执行.远程打 ...