Color the ball HDOJ--1556
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6609 Accepted Submission(s): 3468
当N = 0,输入结束。
思路:线段树题目,感觉是时候学学线段树这种数据结构了,于是找了一题练练,一次AC,爽啊!
成断更新,单点查询!
AC代码:
#include<stdio.h>
#define MAX 100001
typedef struct
{
int left;
int right;
int cover;
}Node;
Node ball[*MAX];
int cnt;
void build(int l,int r,int k)
{
int mid;
if(l == r)
{
ball[k].left = l;
ball[k].right = r;
ball[k].cover = ;
return ;
}
ball[k].left = l;
ball[k].right = r;
ball[k].cover = ;
mid = (l+r) >> ;
build(l,mid,k << );
build(mid+,r,k << |);
} void insert(int l,int r,int k)
{
if(l == ball[k].left && r == ball[k].right)
{
ball[k].cover++;
return ;
}
if(ball[k].right == ball[k].left)
return ;
int mid = (ball[k].left+ball[k].right) >> ;
if(r <= mid)
insert(l,r,k << );
else if(l > mid)
insert(l,r,k << |);
else
{
insert(l,mid,k << );
insert(mid+,r,k << |);
}
return ;
} void search(int num,int k)
{
if(ball[k].left == ball[k].right)
{
cnt += ball[k].cover;
return ;
}
cnt += ball[k].cover;
int mid = (ball[k].left+ball[k].right) >> ;
if(num <= mid)
search(num,k << );
else
search(num,k << |);
return ;
} int main()
{
int n,i;
int a,b;
while(~scanf("%d",&n) && n)
{
build(,n,);
for(i = ;i < n;i ++)
{
scanf("%d%d",&a,&b);
insert(a,b,);
}
for(i = ;i < n;i ++)
{
cnt = ;
search(i,);
printf("%d ",cnt);
}
cnt = ;
search(n,);
printf("%d\n",cnt);
}
return ;
}
Color the ball HDOJ--1556的更多相关文章
- Color the ball HDU - 1556 (非线段树做法)
题意:在1到n的气球中,在不同的区域中涂颜色,问每个气球涂几次. #include<cstdio>int num[100010];int main(){ int n, x, y;; whi ...
- Color the ball HDU - 1556 (线段树)
思路:线段树,区间更新 #include<iostream> #include<vector> #include<string> #include<cmath ...
- A - Color the ball HDU - 1556 (差分数组+前缀和)
思路等引自博客 https://blog.csdn.net/johnwayne0317/article/details/84928568 对数组a[7]: a[0]=1; = d[0] a[1]=1; ...
- 树状数组模板--Color the ball
Color the ball HDU - 1556 N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电 ...
- 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(第二类树状数组 —— 区间更新,点求和)
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 ...
- 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)To ...
随机推荐
- Xcode 7 支持http请求info.plist设置
由于iOS9改用更安全的https,为了能够在iOS9中正常使用http发送网络请求,请在"Info.plist"中进行如下配置,否则影响SDK的使用. 1.找到项目中的 Info ...
- google模拟各种Android手机浏览器方法
在开始--运行 输入 chrome.exe --user-agent="Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/ ...
- JNI学习总结
JNI学习总结 标签(空格分隔): java JNI:Java Native Interface,是一种通过java调用本地方法的技术(当然也可以反过来),随着JDK版本的提升,JNI的效率也一直在提 ...
- 《精通CSS-高级Web标准解决方案》阅读计划
第一周 第1章 基础知识 1 第2章 为样式找到应用目标 1 第3章 可视化格式模型 1 第4章 背景图像效果 1 第二周 第5章 对链接应用样式 1 第6章 对列表应用样 ...
- 原生js的兼容问题总结
获取元素的非行间样式 function getStyle(obj, name) { //获取元素的非行间样式 if (obj.currentStyle) { return obj.currentSty ...
- zTree的getChangeCheckedNodes()使用
zTree的getChangeCheckedNodes()方法用于获取输入框勾选状态被改变的节点集合.如果需要获取每次操作后全部被改变勾选状态的节点数据,请在每次勾选操作后,遍历所有被改变勾选状态的节 ...
- HTML块
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- python三级菜单的实现
一.作业要求 1.使用字典实现三级菜单功能 2.直接输入前面数字进入下一级菜单 3.按B返回上一级,按Q退出 二.需要知识点 1.if循环 2.for循环,enumerate的用法 3.while循环 ...
- 用Python实现的一个简单的随机生成器
朋友在ctr工作,苦于各种排期神马的,让我帮他整一个xxxx管理系统 里面在用户管理上面需要有一个批量从文件导入的功能,我肯定不能用汉字来作唯一性约束,于是想到了随机生成. 我首先想到的是直接用ite ...
- typedef与define基本使用
参考: typedef用法 http://www.cnblogs.com/ggjucheng/archive/2011/12/27/2303238.html#define用法:http://blog. ...