题目链接: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. C++编程中const和#define的区别

    (1) 编译器处理方式不同 define宏是在预处理阶段展开. const常量是编译运行阶段使用.(2) 类型和安全检查不同 define宏没有类型,不做任何类型检查,仅仅是展开. const常量有具 ...

  2. Java:多线程,使用同步锁(Lock)时利用Condition类实现线程间通信

    如果程序不使用synchronized关键字来保证同步,而是直接使用Lock对象来保证同步,则系统中不存在隐式的同步监视器,也就不能用wait().notify().notifyAll()方法进行线程 ...

  3. 碰到sshd连接不上linux时的解决办法

    1,首先更改ssh配置,可以是ssh端口连接不上服务器 cd /etc/ssh/sshd_config vi !$ Port 52113 //ssh默认的连接端口, 改为别人不知道的端口 Permit ...

  4. mke2fs/mks.etc3/fstab/mount指令

    一.mke2fs指令mkfs.etc3 /dev/sdb1指令 主要新学习 cat /etc/filesystem  //查看文件类型 mkfs. tab键有提示    //按照系统默认的值格式化 m ...

  5. git 安装或者更新

    1. 安装编译git时需要的包 # yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel # yum in ...

  6. 用C#用C#实现窗体在规定时间弹出,例如:10:00.弹出后关闭。并在5分钟后再次弹出。5次后停止。最好有具体代码实现窗体在规定时间弹出,例如:10:00.弹出后关闭。并在5分钟后再次弹出。5次后停止。最好有具体代码

    run(){        while(true)        {                show();                if(条件)                {     ...

  7. UVa 11021 - Tribles

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  8. python交互模式下cp65001异常

    unknown encoding: cp65001异常 python安装后进入命令行交互模式,输入任何代码都报unknown encoding: cp65001异常 需要将编码(UTF-8)修改为 简 ...

  9. STL-算法

    #include <algorithm> 1. max_element(v.begin(), v.end()); 注意,所有的区间全部是半开区间,如果数组包含20-40,通过find找出2 ...

  10. “更高效率:标准化+简约风+移动化”--K2 BPM老客户交流会

    主题:工作流主数据标准化和移动工作流带来的企业沟通建设机会 嘉宾:李瑞延(盛大网络IT总监) 公司管理需要更好的工作流 -为决策提供依据 通过对各级业务公司各类流程数据的获取与分析,为管理决策提供必要 ...