题目链接: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(线段树)的更多相关文章

  1. hdu1556 Color the ball 线段树区间染色问题

    都是老套路了,如果n=5,要把区间[1,4]染色,可以递归去染区间[1,3]和区间[4,4],如果区间相等就自加,不相等继续递归寻找对应区间. 打印结果时,把所有到达叶节点包含i的区间值相加,就是最后 ...

  2. HDU1556 Color the ball [线段树模板]

    题意:区间修改序列值,最后输出. //hdu1166 #include<iostream> #include<cstdio> #include<cstring> # ...

  3. HDU.1556 Color the ball (线段树 区间更新 单点查询)

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

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

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

  5. hdu 1556 Color the ball (线段树+代码详解)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  6. hdu 1556 Color the ball(线段树区间维护+单点求值)

    传送门:Color the ball Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/3276 ...

  7. ZOJ 2301 Color the Ball 线段树(区间更新+离散化)

    Color the Ball Time Limit: 2 Seconds      Memory Limit: 65536 KB There are infinite balls in a line ...

  8. HDU 1556 Color the Ball 线段树 题解

    本题使用线段树自然能够,由于区间的问题. 这里比較难想的就是: 1 最后更新须要查询全部叶子节点的值,故此须要使用O(nlgn)时间效率更新全部点. 2 截取区间不能有半点差错.否则答案错误. 这两点 ...

  9. Color the ball (线段树的区间更新问题)

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

  10. hdu 1556 Color the ball 线段树

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

随机推荐

  1. JavaScript实现五子棋的界面设计

    五子棋的界面设计包括绘制棋盘.绘制棋子及黑白棋轮流落子. 涉及的知识点主要有canvas绘制直线.设置画笔颜色:canvas画圆.填充渐变色 1.绘制棋盘 先设定棋盘的宽.高:然后利用for循环,根据 ...

  2. 221. Maximal Square -- 矩阵中1组成的最大正方形

    Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and re ...

  3. SQL批量删除与批量插入

    批量删除: DELETE FROM MyTable WHERE ID IN (1,2); 批量插入: INSERT INTO MyTable(ID,NAME) VALUES(1,'123');INSE ...

  4. sqlserver 修改替换text,ntext类型字段的两种方案

    方案一 用Update和Replace --替换语句(因为varchar(max)最大值是8000,所以大于8000的部分会被截掉) UPDATE dbo.SNS_UserBlog SET [Desc ...

  5. github注册使用以及体会

    一.个人介绍 我叫冯越,学号是1413042065,班级是网络工程143,兴趣爱好有打羽毛球,素描,读书,个人编程能力一般,行数没有计算过,大一学习C++时,实验题目一些书后的题目,大二学习数据结构时 ...

  6. 【转】Session ID/session token 及和cookie区别

    Session + Cookie  知识收集! cookie机制采用的是在客户端保持状态的方案.它是在用户端的会话状态的存贮机制,他需要用户打开客户端的cookie支持.cookie的作用就是为了解决 ...

  7. 【转】数据库范式(1NF 2NF 3NF BCNF)详解一

    以下内容转自:http://jacki6.iteye.com/blog/774866 --------------------------------------------分割线---------- ...

  8. webapi方式

    随笔 - 112  文章 - 0  评论 - 334 ASP.NET MVC学习系列(二)-WebAPI请求   继续接着上文 ASP.NET MVC学习系列(一)-WebAPI初探 来看看对于一般前 ...

  9. linux 系统安装 mysql

    安装mysql所需要的依赖环境 yum -y install gcc gcc-c++ gcc-g77 autoconf automake zlib*  libxml* ncurses-devel li ...

  10. C#图书资源【更新中...】喜欢的就转存吧

    百度分享暂时取消了,需要的朋友可以直接关注我,我发给你. 重点篇 1.C#与.NET3.5高级程序设计 2.C#与.NET3.5高级程序设计.rar 3.Effective_C#_中文版_改善C#程序 ...