线段树(求单结点) hdu 1556 Color the ball
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 22122 Accepted Submission(s): 10715
当N = 0,输入结束。
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#define ls (u<<1)
#define rs (u<<1|1)
using namespace std; int ans[],n; struct node{
int l,r,n;
} node[]; void build(int u,int l,int r){
node[u].l = l;
node[u].r = r;
node[u].n = ;
if(l!=r){
int mid = (l+r)>>;
build(ls,l,mid);
build(rs,mid+,r);
}
} void update(int u,int x,int y){
if(node[u].l == x && node[u].r == y)//找到要刷的气球区间,更新其被刷的次数+1
node[u].n++;
else{
int mid = (node[u].l+node[u].r)>>;
if(y<=mid)
update(ls,x,y);
else if(x>mid)
update(rs,x,y);
else{
update(ls,x,mid);
update(rs,mid+,y);
}
}
} void query(int u){
for(int i = node[u].l; i<=node[u].r; i++)//该区间所有编号都被刷了一次
ans[i]+=node[u].n;//求单结点
if(node[u].l == node[u].r)
return;
query(ls);
query(rs);
} int main(){
int x,y;
while(cin >> n,n){
build(,,n);
for(int i = ; i<=n; i++){
cin >> x >> y;
update(,x,y);
}
memset(ans,,sizeof(ans));
query();
cout << ans[];
for(int i = ; i<=n; i++)
cout << " " << ans[i];
cout << endl;
}
return ;
}
线段树(求单结点) hdu 1556 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 ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- 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 Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/3276 ...
- HDU 1556 Color the ball(线段树:区间更新)
http://acm.hdu.edu.cn/showproblem.php?pid=1556 题意: N个气球,每次[a,b]之间的气球涂一次色,统计每个气球涂色的次数. 思路: 这道题目用树状数组和 ...
- hdu 1556 Color the ball 线段树
题目链接:HDU - 1556 N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气 ...
- 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 ballTime Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
随机推荐
- Android:JNI与NDK(三)NDK构建的脚本文件配置
友情提示:欢迎关注本人公众号,那里有更好的阅读体验以及第一时间获取最新文章 本文目录 一.前言 本篇我们介绍Android.mk与CMakeLists.txt构建NDK的配置文件,我们知道目前NDK的 ...
- 03、Swagger2和Springmvc整合详细记录(爬坑记录)
时间 内容 备注 2018年6月18日 基本使用 spirngmvc整合swagger2 开始之前这个系列博文基本是,在项目的使用中一些模块的内容记录,但是后期逐渐优化,不单单是整合内容. swagg ...
- 给面试官讲明白:一致性Hash的原理和实践
"一致性hash的设计初衷是解决分布式缓存问题,它不仅能起到hash作用,还可以在服务器宕机时,尽量少地迁移数据.因此被广泛用于状态服务的路由功能" 01分布式系统的路由算法 假设 ...
- 使用JMS接口接入WebSphere MQ消息
在你的应用程序中利用IBM WebSphere MQ消息中间件提供Java消息服务开放接口. IBM WebSphere MQ(WMQ)是一套面向消息的中间件(message-oriented mid ...
- SonarQube系列二、分析dotnet core/C#代码
[前言] 本系列主要讲述sonarqube的安装部署以及如何集成jenkins自动化分析.netcore项目.目录如下: SonarQube系列一.Linux安装与部署 SonarQube系列二.分析 ...
- Window.open使用总结
前言 今天在项目中,突然看到window.open的使用,感觉还是很神奇,突然心血来潮查看了window.open的用法. 用途 主要用于在打开网站时弹出的其他窗口.用于通知广告一类的. 用法 win ...
- tensorflow学习笔记——多线程输入数据处理框架
之前我们学习使用TensorFlow对图像数据进行预处理的方法.虽然使用这些图像数据预处理的方法可以减少无关因素对图像识别模型效果的影响,但这些复杂的预处理过程也会减慢整个训练过程.为了避免图像预处理 ...
- Hive 系列(四)—— Hive 常用 DDL 操作
一.Database 1.1 查看数据列表 show databases; 1.2 使用数据库 USE database_name; 1.3 新建数据库 语法: CREATE (DATABASE|SC ...
- jquery validate常用方法及注意问题
1. required: true 值是必须的.required: "#aa:checked" 表达式的值为真,则需要验证.required: function(){} 返回为真, ...
- vim文件时,误用了ctrl+z命令,该怎么办?
linux中,当正在使用vim命令编辑文件,退出时,如果误使用了 ctrl+z ,当前目录中会多一个隐藏文件. 比如我正在编辑 t.txt 文件时,误以为我之前使用的是 tail 命令,直接使用 ct ...