水一下

#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 线段树 区间更新的更多相关文章

  1. HDU.1556 Color the ball (线段树 区间更新 单点查询)

    HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...

  2. HDU 1556 Color the ball(线段树区间更新)

    Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...

  3. hdu 1556 Color the ball(线段树区间维护+单点求值)

    传送门:Color the ball Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/3276 ...

  4. hdu 1556 Color the ball (线段树+代码详解)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  5. hdu 1556 Color the ball 线段树

    题目链接:HDU - 1556 N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气 ...

  6. HDU 1556 Color the Ball 线段树 题解

    本题使用线段树自然能够,由于区间的问题. 这里比較难想的就是: 1 最后更新须要查询全部叶子节点的值,故此须要使用O(nlgn)时间效率更新全部点. 2 截取区间不能有半点差错.否则答案错误. 这两点 ...

  7. Color the ball 线段树 区间更新但点查询

    #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #inclu ...

  8. hdu1556Color the ball线段树区间更新

    题目链接 线段树区间更新更新一段区间,在更新区间的过程中,区间被分成几段,每一段的左右界限刚好是一个节点的tree[node].left和tree[node].right(如果不是继续分,直到是为止) ...

  9. (简单) HDU 1698 Just a Hook , 线段树+区间更新。

    Description: In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of ...

随机推荐

  1. Linux 用 ps 與 top 指令找出最耗費 CPU 與記憶體資源的程式最占cpu的进程

    Linux 用 ps 與 top 指令找出最耗費 CPU 與記憶體資源的程式 2016/12/220 Comments  ######### ps -eo pid,ppid,%mem,%cpu,cmd ...

  2. Chm文件阅读软件测试需求

    转发: .Chm文件阅读软件测试需求 . xchm问题太多就不考虑了: kchm是问题少一些 windows打开是乱码就不去考虑 必须在windows打开正常的再在龙芯上打开 1windows打开是乱 ...

  3. linux patch中的p0和p1的区别

    命令patch的主要作用是生成diff文件和应用diff文件.举个例子来讲,当发现某个程序出现bug需要打补丁时,patch便是一个好工具. diff文件头: [root@localhost kern ...

  4. DOCKER学习_014:Docker存储补充

    在前面已经学习了Docker的存储,https://www.cnblogs.com/zyxnhr/p/11830238.html,现在对前面的内容的一个补充,具体请参考https://www.cnbl ...

  5. DOCKER学习_011:使用Dockerfile制作docker镜像

    前面使用commit的方式,制作一个docker镜像,本次介绍使用Dockerfile制作一个dockers镜像 [root@docker-server3 ~]# mkdir /openssh [ro ...

  6. centos7安装google-chrome

    完整的安装步骤:https://www.tecmint.com/install-google-chrome-on-redhat-centos-fedora-linux/ 1.简单安装测试版:sudo ...

  7. 使用nuget包下载Entity Framework6.0无法使用模型类与数据库上下文自动生成controller与view

    解决方法:卸载掉原有的6.0版本EF,从控制台安装5.0版本的. >工具>库程序包管理器>程序包管理器控制台.在PM>后面输入安装命令. 命令如下 Install-Packag ...

  8. 10.7 netstat:查看网络状态

    netstat命令 用于显示本机网络的连接状态.运行端口和路由表等信息. netstat命令的参数选项及说明 -r 显示路由表信息,该功能类似于前面学过的route 和ip route-g 显示多播功 ...

  9. Oracle和MySQL差异总结

    常用功能差异 锁差异: • Oracle锁加在数据块上 • InnoDB 是在索引上加锁,所以MySQL锁的粒度没有Oracle 精细. 导入导出: • Oracle采用EXP /IMP ,EXPDP ...

  10. 【三】Kubernetes学习笔记-Pod 生命周期与 Init C 介绍

    一.容器生命周期 Init C(初始化容器)只是用于 Pod 初始化的,不会一直随着 Pod 生命周期存在,Init C 在初始化完成之后就会死亡. 一个 Pod 可以有多个 Init C,也可以不需 ...