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 ...
随机推荐
- 基于多主机的Web服务
[Centos7.4版本] !!!测试环境我们首关闭防火墙和selinux [root@localhost ~]# systemctl stop firewalld [root@localhost ~ ...
- 用于监视Linux上的内存使用情况的Bash脚本
用于监视Linux上的内存使用情况的Bash脚本 2019-06-17 11:32:45作者:戴进稿源:云网牛站 在本文中,我们添加了两个shell脚本来监视Linux操作系统上的内存利用率,即用于监 ...
- zabbix监控之用户及用户组
一.概述 Zabbix 中的所有用户都通过 Web 前端去访问 Zabbix 应用程序.并为每个用户分配唯一的登陆名和密码. 所有用户的密码都被加密并储存于 Zabbix 数据库中.用户不能使用其用户 ...
- Java必会之多线程
一.线程的基本知识 1.1 线程知识 进程和线程的关系和区别 线程: 线程是进程的基本执行单元,进程想要执行任务,必须要有线程.程序启动默认开启一条线程,这个线程被称为主线程. 进程: 进程是指在系统 ...
- 2. Servlet3.0注解方式 @WebServlet
web.xml配置还是比较麻烦,这次使用注解方式 编写servlet import javax.servlet.ServletException; import javax.servlet.annot ...
- Step By Step(Lua迭代器和泛型for)
Step By Step(Lua迭代器和泛型for) 1. 迭代器与Closure: 在Lua中,迭代器通常为函数,每调用一次函数,即返回集合中的"下一个"元素.每个迭代器都 ...
- springboot项目添加swagger2
1.pom中添加swagger依赖 <!-- swagger-ui --> <dependency> <groupId>io.springfox</group ...
- 『动善时』JMeter基础 — 37、将JMeter测试结果写入Excel
目录 1.环境准备 (1)引入操作Excel文件的基础JAR包 (2)引入封装自定义操作Excel文件的JAR包 2.准备测试需要的数据 3.测试结果写入Excel演示 (1)测试计划内包含的元件 ( ...
- 人工智能AI Boosting HMC Memory Chip
人工智能AI Boosting HMC Memory Chip Innosilicon的AI Boosting HMC存储芯片适用于高速,高带宽和高性能存储领域,例如AI边缘,数据中心,自动化等. H ...
- ARM CPU自动调度神经网络
ARM CPU自动调度神经网络 对特定设备和工作负载进行自动调度,对于获得最佳性能至关重要.通过RPC使用自动调度器为ARM CPU调度整个神经网络. 为了自动调度神经网络,将网络划分为小的子图,进行 ...