hdu 1556 Color the ball 线段树 区间更新
水一下
#include <bits/stdc++.h>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
using namespace std; const int MAXN = 111111;
int sum[MAXN<<2];
int n; void push_down(int rt, int len)
{
if(sum[rt] == 0) return;
sum[rt<<1] += sum[rt];
sum[rt<<1|1] += sum[rt];
sum[rt] = 0;
} void update(int L, int R, int l, int r, int rt)
{
if(L <= l && r <= R)
{
sum[rt]++;
return;
}
push_down(rt, r - l + 1);
int m = (l + r) >> 1;
if(m >= L) update(L, R, lson);
if(m < R) update(L, R, rson);
} void query(int l, int r, int rt)
{
if(l == r)
{
printf("%d%c", sum[rt], l == n? '\n':' ');
return;
}
push_down(rt, r - l + 1);
int m = (l + r) >> 1;
query(lson);
query(rson);
} int main()
{
// freopen("in.txt", "r", stdin);
while(~scanf("%d", &n) && n)
{
memset(sum, 0, sizeof(sum));
int m = n;
while(m--)
{
int a, b;
scanf("%d%d", &a, &b);
update(a, b, 1, n, 1);
}
query(1, n, 1);
}
return 0;
}
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 Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/3276 ...
- 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 线段树
题目链接:HDU - 1556 N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气 ...
- HDU 1556 Color the Ball 线段树 题解
本题使用线段树自然能够,由于区间的问题. 这里比較难想的就是: 1 最后更新须要查询全部叶子节点的值,故此须要使用O(nlgn)时间效率更新全部点. 2 截取区间不能有半点差错.否则答案错误. 这两点 ...
- Color the ball 线段树 区间更新但点查询
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #inclu ...
- hdu1556Color the ball线段树区间更新
题目链接 线段树区间更新更新一段区间,在更新区间的过程中,区间被分成几段,每一段的左右界限刚好是一个节点的tree[node].left和tree[node].right(如果不是继续分,直到是为止) ...
- (简单) HDU 1698 Just a Hook , 线段树+区间更新。
Description: In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of ...
随机推荐
- Linux系统(控制节点)部署环境
环境部署 重点说明:安装ansible时去控制Windows机器,由于需要在Linux系统上安装pywinrm插件,而使用yum安装锝ansible是无法调用pywinrm插件,所以整体使用pip工具 ...
- 搭建LNMP环境部署Wordpress博客
!!!首先要做的就是关闭系统的防火墙以及selinux: #systemctl stop firewalld #systemctl disable firewalld #sed -ri 's/^(SE ...
- DHCP与DHCP中继
DHCP原理与配置 1. DHCP应用场景 2. DHCP报文类型 3. DHCP工作原理 4. IP地址获取与释放 5. DHCP中继配置 1. DHCP应用场景 在大型企业网络中,会有大量的主机或 ...
- Docker学习(2) 安装
1 在Ubanru中安装 简单安装: 2 windows安装docker 3 OS X 安装docker
- Darknet_Yolov3模型搭建
Darknet_Yolov3模型搭建 YOLO(You only look once)是目前流行的目标检测模型之一,目前最新已经发展到V3版本了,在业界的应用也很广泛.YOLO的特点就是"快 ...
- CodeGen用户定义的扩展令牌
CodeGen用户定义的扩展令牌 用户定义的扩展令牌是一种特殊的令牌,开发人员可以确定令牌的名称以及在代码生成过程中遇到令牌时要插入的值. CodeGen支持多种机制,允许通过以下方式实现用户定义的令 ...
- Seata分布式事务框架Sample
前言 阿里官方给出了seata-sample地址,官方自己也对Sample提供了很多类型,可以查看学习. 我这里选择演示SpringBoot+MyBatis. 该聚合工程共包括5个module: sb ...
- C语言代码区错误以及编译过程
C语言代码区错误 欲想了解C语言代码段会有如何错误,我们必须首先了解编译器是如何把C语言文本信息编译成为可以执行的机器码的. 背景介绍 测试使用的C语言代码 导入标准库,定义宏变量,定义结构体,重命名 ...
- 三色标记法与读写屏障, G1工作过程
https://www.jianshu.com/p/12544c0ad5c1 https://www.cnblogs.com/GrimMjx/p/12234564.html 自我总结和记忆: 为了解决 ...
- mybatis——一级缓存、二级缓存
一.Mybatis缓存 ● MyBatis包含一个非常强大的查询緩存特性,它可以非常方便地定制和配置缓存.绶存可以极大的提升查询效率. ● MyBatis系统中默认定义了两级缓存:一级缓存和二级缓存 ...