简单线段树。

 #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. centos7安装chrome的历程(fedora同)

    安装 首先是下载,地址奉上:http://www.google.cn/chrome/browser/desktop/index.html,选择64 bit .rpm (适用于 Fedora/openS ...

  2. mysql left用法

    LEFT(str,len) 返回字符串str的最左面len个字符. SELECT LEFT('123456789',5)

  3. Animating Layout Changes(展开收起)

    原文地址:https://developer.android.com/training/animation/layout.html#add (1)设置布局文件: <LinearLayout an ...

  4. python基础知识十一

    图形软件 使用Python的GUI库——你需要使用这些库来用Python语言创建你自己的图形程序.使用GUI库和它们的Python绑定,你可以创建你自己的IrfanView.Kuickshow软件或者 ...

  5. html-----001

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. JavaScript设置右下角悬浮窗

    很多时候,我们需要设置一个dom节点到浏览器窗口的右下角.我们需要那个元素可以在窗口Scroll滚动或者变换大小resize的时候都可以保持浮动在那个位置.这个时候,我在网上看了看,发现很多框架什么啊 ...

  7. WPF 窗体中的 Canvas 限定范围拖动 鼠标滚轴改变大小

    xaml代码: <Canvas Name="movBg"> <Canvas.Background> <LinearGradientBrush EndP ...

  8. 速卖通api--发起授权

    <? $reqURL_onLine = "https://gw.api.alibaba.com/openapi/http/1/system.oauth2/getToken/494739 ...

  9. shell命令:echo命令详解

    功能说明:显示文字. 语 法:echo [-ne][字符串] / echo [--help][--version] 补充说明:echo会将输入的字符串送往标准输出.输出的字符串间以空白字符隔开, 并在 ...

  10. 算法专题训练 搜索a-T3 Ni骑士(ni)

    搞了半天八数码弄不出来就只好来打题解  这道题是在搜索a碰到的(链接: http://pan.baidu.com/s/1jG9rQsQ ) 感觉题目最大亮点就是这英文简写"ni", ...