hdu 1556 Color the ball (线段树做法)
Problem Description
Input
当N = 0,输入结束。
Output
#include<stdio.h>
#pragma comment(linker,"/STACk:1024000000,1024000000")
struct CNode
{
int L,R;
//int nSum;
int Inc;
CNode *pLeft,*pRight;
};
CNode Tree[];
int nCount;
int Mid(CNode *pRoot)
{
return (pRoot->L+pRoot->R)/;
}
void BuildTree(CNode *pRoot,int L,int R)
{
pRoot->L=L;
pRoot->R=R;
//pRoot->nSum=0;
pRoot->Inc=;
if(L==R)
return ;
nCount++;
pRoot->pLeft=Tree+nCount;
nCount++;
pRoot->pRight=Tree+nCount;
BuildTree(pRoot->pLeft,L,(L+R)/);
BuildTree(pRoot->pRight,(L+R)/+,R);
}
/*void Insert(CNode *pRoot,int i,int v)
{
if(pRoot->L==i&&pRoot->R==i)
{
pRoot->nSum=v;
return ;
}
pRoot->nSum+=v;
if(i<=Mid(pRoot))
Insert(pRoot->L,i,v);
else
Insert(pRoot->R,i,v);
}*/
void Add(CNode *pRoot,int a,int b)
{
if(pRoot->L==a&&pRoot->R==b)
{
pRoot->Inc++;
return ;
}
//pRoot->nSum+=c*(b-a+1);
if(b<=Mid(pRoot))
Add(pRoot->pLeft,a,b);
else if(a>=Mid(pRoot)+)
Add(pRoot->pRight,a,b);
else
{
Add(pRoot->pLeft,a,Mid(pRoot));
Add(pRoot->pRight,Mid(pRoot)+,b);
}
}
int ans;
int QuerySum(CNode *pRoot,int a,int b,int i)
{
ans+=pRoot->Inc;
if(pRoot->L==i&&pRoot->R==i)
return ans;//pRoot->nSum+(pRoot->R-pRoot->L+1)*pRoot->
//pRoot->nSum+=(pRoot->R-pRoot->L)*pRoot->Inc; //Add(pRoot->pLeft,pRoot->L,Mid(pRoot),pRoot->Inc);
//Add(pRoot->pRight,Mid(pRoot)+1,pRoot->R,pRoot->Inc);
//pRoot->Inc=0;
if(i<=Mid(pRoot))
return QuerySum(pRoot->pLeft,a,b,i);
else //(i>=Mid(pRoot)+1)
return QuerySum(pRoot->pRight,a,b,i);
/*else
{
return QuerySum(pRoot->pLeft,a,Mid(pRoot),i)
+QuerySum(pRoot->pRight,Mid(pRoot)+1,b,i);
}*/
}
int main()
{
int n,a,b,i;
while(scanf("%d",&n)!=EOF&&n)
{
nCount=;
BuildTree(Tree,,n); for(i=;i<n;i++)
{
scanf("%d%d",&a,&b);
Add(Tree,a,b);
}
for(i=;i<n;i++)
{
ans=;
printf("%d ",QuerySum(Tree,,n,i));
}
ans=;
printf("%d\n",QuerySum(Tree,,n,n));
}
return ;
}
hdu 1556 Color the ball (线段树做法)的更多相关文章
- 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 ...
- hdu 1556 Color the ball 线段树
题目链接:HDU - 1556 N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气 ...
- HDU 1556 Color the Ball 线段树 题解
本题使用线段树自然能够,由于区间的问题. 这里比較难想的就是: 1 最后更新须要查询全部叶子节点的值,故此须要使用O(nlgn)时间效率更新全部点. 2 截取区间不能有半点差错.否则答案错误. 这两点 ...
- hdu 1556 Color the ball 线段树 区间更新
水一下 #include <bits/stdc++.h> #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 ...
- hdu 1556 Color the ball (树状数组)
Color the ballTime Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu 1556 Color the ball(树状数组)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 题意:N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数[a,b]之间的气球 ...
- HDU 1556 Color the ball (树状数组 区间更新+单点查询)
题目链接 Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽&quo ...
随机推荐
- 转载关于Qsys的 指令总线 和 数据总线
1.关于Qsys的 指令总线 和 数据总线 连接的问题(data_master和instruction_master) 关于数据和指令端口的连接的疑问,这是初用Qsys的童鞋们很困惑的问题,之前使 ...
- LG3628 [APIO2010]特别行动队
题意 你有一支由 n 名预备役士兵组成的部队,士兵从 1 到 n 编号,要将他们拆分 成若干特别行动队调入战场.出于默契的考虑,同一支特别行动队中队员的编号 应该连续,即为形如(i, i + 1, . ...
- 阿里云接口异常-Can not find endpoint to access
最近在做公司的资产盘点,需要请求阿里云的接口获取公司的云服务器信息.在获取实例列表的过程中,通过异常机制捕获了 Can not find endpoint to access 这个错误.经过多次排查, ...
- fn project hot functions 说明
1. 简单介绍 所谓 hot functions 实际上就是长时间运行的functions ,简单理解类似后台任务 2. fnproject 处理的方式 fnproject 使用 类似 http的 ...
- Python 函数 -slice()
功能: slice() 函数实现切片对象,主要用在切片操作函数里的参数传递.返回一个切片对象. 语法: class slice(stop) class slice(start, stop[, step ...
- Ambari的API调用
GET api/v1/clusters/HDP/configurations可以获得所有的配置信息(例如,http://hdp0:8080/api/v1/clusters/HDP/configurat ...
- contOS 下安装mysql
一.mysql简介 说到数据库,我们大多想到的是关系型数据库,比如mysql.oracle.sqlserver等等,这些数据库软件在windows上安装都非常的方便,在Linux上如果要安装数据库,咱 ...
- Go基本语句
递增递减语句 在GO中,++与--是作为语句而并不是作为表达式 package main import "fmt" func main() { a:= //a=a++ //语句而非 ...
- 【转】关于一个Jmeter interface testing的实例
目标:测试某个保险系统的费率接口 准备:a 请求方式:Http b 接口地址://10.1.1.223:9090/rulesEngine/executeRateRule.do Jmeter 设置: a ...
- 2015 浙江省赛B Team Formation (技巧,动归)
Team Formation For an upcoming programming contest, Edward, the headmaster of Marjar University, is ...