线段树(求单结点) 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 ...
随机推荐
- 结构型设计模式——适配器模式(Go)
适配器模式: 适配器模式是用于当别人提供的对象或接口中的方法或者其它属性啥的和我们的重复了,或者看的不顺眼.名字太长了记不住,而将其包装到一个对象中,然后通过你感觉自己舒服的方式或者方法名字去间接的调 ...
- vue面试题整理vuejs基础知识整理
初级参考 1.v-show 与 v-if 区别 v-show 是css隐藏,v-if是直接销毁和创建,所以频繁切换的适合用v-show 2.计算属性和 watch 的区别 计算属性是自动监听依赖值的变 ...
- cs231n---强化学习
介绍了基于价值函数和基于策略梯度的两种强化学习框架,并介绍了四种强化学习算法:Q-learning,DQN,REINFORCE,Actot-Critic 1 强化学习问题建模 上图中,智能体agent ...
- (十二)c#Winform自定义控件-分页控件
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- 【java提高】(18)---静态内部类和非静态内部类
java提高](18)-静态内部类和非静态内部类 定义 放在一个类的内部的类我们就叫内部类. 自己从开发到现在其实用到内部类主要在两个地方会考虑用内部类: 1.使用静态内部类的单例模式 2.将Json ...
- Flink 源码解析 —— Standalone Session Cluster 启动流程深度分析之 Task Manager 启动
Task Manager 启动 https://t.zsxq.com/qjEUFau 博客 1.Flink 从0到1学习 -- Apache Flink 介绍 2.Flink 从0到1学习 -- Ma ...
- oracle 正则表达的使用
最近遇到有个项目,需要根据文件存储的根目录地址来判断是在云端获取,还是本地获取, 先看下具体有几个不同的根目录: , , 'i') from pmc.designmaterial d 去重关键字:di ...
- django 获取当前访问的URL
next_url = request.path_info print(next_url) print(request.get_full_path()) //打印出全路径(路径和参数) print(re ...
- 前端中的设计模式 JavaScript
最近再准备秋招,然后顺便把过去空白的设计模式相关概念补一补,这些内容都是从<JavaScript设计模式与开发实践>一书中整理出来的 (1)单例模式 定义:保证一个类仅有一个实例,并提供一 ...
- import 和from…import
import 和from-import 一.import模块名 import time print(time.time()) import首次导入模块发生了3件事: 使用import time导入的时 ...