HDU1556-color the ball(线段树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556
#include<cstdio>
using namespace std;
struct node
{
int start;
int end;
int num;
};
node q[500000];
void built(int s,int e,int key)
{
q[key].start=s;
q[key].end=e;
q[key].num=0;
if(s==e)
{
return;
}
int mid=(s+e)/2;
built(s,mid,2*key);
built(mid+1,e,2*key+1);
}
void updata(int i,int j,int key)
{
if(q[key].start==i&&q[key].end==j)
{
q[key].num++;
return;
}
int mid=(q[key].start+q[key].end)/2;
if(i<=mid&&j>mid)
{
updata(i,mid,2*key);
updata(mid+1,j,2*key+1);
}
else
{
if(i<=mid)
updata(i,j,2*key);
if(j>mid)
updata(i,j,2*key+1);
}
}
void insert(int i,int j,int key)
{
if(key!=1)
q[key].num+=q[key/2].num;
if(q[key].start==q[key].end)
{
return;
}
int mid=(q[key].start+q[key].end)/2;
if(i<=mid)
insert(i,j,2*key);
if(j>mid)
insert(i,j,2*key+1);
}
int check(int i,int key)
{
if(q[key].start==q[key].end)
return q[key].num;
int mid=(q[key].start+q[key].end)/2;
if(i<=mid)
check(i,2*key);
else
check(i,2*key+1);
}
int main()
{
int N,a,b,i;
while(scanf("%d",&N)&&N)
{
built(1,N,1);
for(i=1;i<=N;i++)
{
scanf("%d%d",&a,&b);
updata(a,b,1);
}
insert(1,N,1);
printf("%d",check(1,1));
for(i=2;i<=N;i++)
printf("% d",check(i,1));
printf("\n");
}
return 0;
}
HDU1556-color the ball(线段树)的更多相关文章
- hdu1556 Color the ball 线段树区间染色问题
都是老套路了,如果n=5,要把区间[1,4]染色,可以递归去染区间[1,3]和区间[4,4],如果区间相等就自加,不相等继续递归寻找对应区间. 打印结果时,把所有到达叶节点包含i的区间值相加,就是最后 ...
- HDU1556 Color the ball [线段树模板]
题意:区间修改序列值,最后输出. //hdu1166 #include<iostream> #include<cstdio> #include<cstring> # ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- HDU 1556 Color the ball(线段树区间更新)
Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...
- hdu 1556 Color the ball (线段树+代码详解)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu 1556 Color the ball(线段树区间维护+单点求值)
传送门:Color the ball Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/3276 ...
- ZOJ 2301 Color the Ball 线段树(区间更新+离散化)
Color the Ball Time Limit: 2 Seconds Memory Limit: 65536 KB There are infinite balls in a line ...
- HDU 1556 Color the Ball 线段树 题解
本题使用线段树自然能够,由于区间的问题. 这里比較难想的就是: 1 最后更新须要查询全部叶子节点的值,故此须要使用O(nlgn)时间效率更新全部点. 2 截取区间不能有半点差错.否则答案错误. 这两点 ...
- Color the ball (线段树的区间更新问题)
N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色.但 ...
- hdu 1556 Color the ball 线段树
题目链接:HDU - 1556 N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气 ...
随机推荐
- hdu-------(1698)Just a Hook(线段树区间更新)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- CSS 声明( Declarations )
CSS 声明1可以为空,或者由 CSS 特性( property ),后加一个冒号 ":",跟着是一个特性的值构成.中间可以有空格将它们隔开. 可用以下方式表达: property ...
- 关于html中table表格tr,td的高度和宽度
关于html中table表格tr,td的高度和宽度 关于html中table表格tr,td的高度和宽度 做网页的时候经常会遇到各种各样的问题,经常遇到的一个就是会碰到表格宽度对不齐的问题.首先,来分析 ...
- mouseover 和 hover 方法
mouseover 和 hover 方法的不同?jquery hover包括了鼠标移到对象上,同时鼠标再移出对象的过程,相应的子类也被选中. mouseover是鼠标经过对象时,不包含他的子类同时 ...
- this和super关键字
this关键字: 1.引用成员变量 2.通过this(参数列表)调用类的重载的构造方法 3.返回对象的值:使用return this,来返回某个类的引用. super关键字: 1.super是一个引用 ...
- Storm(3) - Calculating Term Importance with Trident
Creating a URL stream using a Twitter filter Start by creating the project directory and standard Ma ...
- Swift - 自动布局库SnapKit的使用详解3(约束优先级,约束做动画)
1,约束优先级我们使用SnapKit的时候,还可以定义约束的优先级.这样当约束出现冲突的时候,优先级高的约束覆盖优先级低的约束.具体优先级可以放在约束链的结束处. (1)可以设置如下几种优先级 pri ...
- bzoj 1854: [Scoi2010]游戏
#include<cstdio> #include<iostream> #include<cstring> #define M 2000008 using name ...
- checkbox全选功能
$("#cb_classType_all").change(function () { if ($(this).is(":checked")) { $(&quo ...
- limit 百万级数据分页优化方法
mysql教程 这个数据库教程绝对是适合dba级的高手去玩的,一般做一点1万 篇新闻的小型系统怎么写都可以,用xx框架可以实现快速开发.可是数据量到了10万,百万至千万,他的性能还能那么高吗? 一点小 ...