线段树(求单结点) 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 ...
随机推荐
- Activiti6系列(1)- 核心数据库表及字段注释说明
前言 本文是根据<疯狂工作流讲义-Activiti6.0>一书中提取过来的,有兴趣的可以去当当网买这本书,讲的很不错,最后还有实战案例. 虽然是提取过来的,但完全靠手打梳理,觉得有用的小伙 ...
- CentOS yum 源修改
修改 CentOS 默认 yum 源为 mirrors.163.com 首先备份系统自带yum源配置文件/etc/yum.repos.d/CentOS-Base.repo [root@localhos ...
- HDU 4635 (完全图 和 有向图缩点)
题目链接:HDU 4635 题目大意: 给你一个有向图,加有向边,使得这个图是简单有向图.问你最多加多少条有向边. 简单有向图: 1.不存在有向重边. 2.不存在图循环.(注意是不存在 “图” 循环 ...
- 第三方登录之QQ
public class MainActivity extends AppCompatActivity { private Button btn; private TextView tv; priva ...
- Python 学习笔记(6)— 字符串格式化
字符串格式化处理 远古写法 以前通常使用运算符号 % ,%s 插入的值 String 类型,%.3f 指插入的值为包含 3 位小数的浮点数: format1 = "%s, %s!" ...
- 【Python3爬虫】学习分布式爬虫第一步--Redis分布式爬虫初体验
一.写在前面 之前写的爬虫都是单机爬虫,还没有尝试过分布式爬虫,这次就是一个分布式爬虫的初体验.所谓分布式爬虫,就是要用多台电脑同时爬取数据,相比于单机爬虫,分布式爬虫的爬取速度更快,也能更好地应对I ...
- c# 20160721
ctrl y =>反撤销 ctrl m m 隐藏当前代码段 重载运算符语法 把事件处理程序注册为 click事件的监听程序 [newButton.click+=newButton_click] ...
- abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十四)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...
- Go_笔试题记录-不熟悉的
1.golang中没有隐藏的this指针,这句话的含义是() A. 方法施加的对象显式传递,没有被隐藏起来 B. golang沿袭了传统面向对象编程中的诸多概念,比如继承.虚函数和构造函数 C. go ...
- webservice接口和http接口(API接口)的区别
web service(SOAP)与HTTP接口的区别: 什么是web service? 答:soap请求是HTTP POST的一个专用版本,遵循一种特殊的xml消息格式Content- ...