【HDOJ】1556 Color the ball
简单线段树。
#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的更多相关文章
- HDOJ/HDU 1556 Color the ball(树状数组)
Problem Description N个气球排成一排,从左到右依次编号为1,2,3-.N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动车从 ...
- hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1556:Color the ball(线段树,区间更新,经典题)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- 【AGC025B】RGB Color
[AGC025B]RGB Color 题面描述 Link to Atcoder Link to Luogu Takahashi has a tower which is divided into \( ...
- hdoj 1556 Color the ball【线段树区间更新】
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 1556 Color the ball【差分数组裸题/模板】
N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一 ...
- HDU 1556 Color the ball【算法的优化】
/* 解题思路:每次仅仅求解一開始的第一个数字,让第一个数字加一,最后的一个数字的后面一个数减一.我们能够想想,最后加的时候,就是加上前面一个数出现的次数和自己本身出现的次数. 解题人:lingnic ...
- HDU 1556 Color the ball(线段树区间更新)
Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...
随机推荐
- iOS开发中.pch 文件的使用及其相关工程设置
.pch文件 也是一个头文件,pch头文件的内容能被项目中的其他所有源文件共享和访问.是一个预编译文件. 首先说一下pch的作用: 1.存放一些全局的宏(整个项目中都用得上的宏) 2.用来包含一些全部 ...
- sybase SA密码重置
sa 密码忘记解决之道: su - sybase cd ASE/install vi RUN_etoh2 在文件的末尾加入 -psa \ 停止原数据库服务 由于密码遗忘,所以只能通过kill进程停止服 ...
- ubuntu16.04 : 4: [: y: unexpected operator
Ubuntu16.04 执行行脚本出错 在使用sh 执行脚本 出错标志 : 4: [: y: unexpected operator 原因:sh是连接到dash的,又因为dash跟bash的不兼容所以 ...
- JSTL时间比较,jstl日期比较,jsp比较时间
>>>>>>>>>>>>>>>>>>>>>>>>> ...
- CSS权威指南-第三版--读书笔记
第一章:CSS和文档 html是结构化语言,css是样式语言,html主要用来被强大的搜索引擎更好的索引,更好的让一个盲人通过语音浏览器来了解我们的网页,这也就是为什么说html是结构话语言,因为这是 ...
- 如何打包成jar包自己看呢?
第一步:选择你要导出的部分 第二步:
- (转)ASP.NET QueryString乱码解决问题
正常的情况下,现在asp.net的网站很多都直接使用UTF8来进行页面编码的,这与Javascript.缺省网站的编码是相同的,但是也有相当一部分采用GB2312. 对于GB2312的网站如果直接用j ...
- [序列化] Serialize--序列化帮助类 (转载)
点击下载 Serialize.zip 这个类是关于加密,解密的操作,文件的一些高级操作1.序列化2.要序列化的类3.序列化例子看下面代码吧 /// <summary> /// 类说明:As ...
- SOCKET,TCP/UDP,HTTP,FTP
(一)TCP/UDP,SOCKET,HTTP,FTP简析 TCP/IP是个协议组,可分为三个层次:网络层.传输层和应用层: 网络层:IP协议.ICMP协议.ARP协议.RARP协议和BOOTP协议 传 ...
- 给分类(Category)添加属性
遇到一个问题,写了一个分类,但原先类的属性不够用.添加一个属性,调用的时候崩溃了,说是找不到getter.setter方法.查了下文档发现,OC的分类允许给分类添加属性,但不会自动生成getter.s ...