http://acm.hdu.edu.cn/showproblem.php?pid=1556

Problem Description
N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色。但是N次以后lele已经忘记了第I个气球已经涂过几次颜色了,你能帮他算出每个气球被涂过几次颜色吗?
 
Input
每个测试实例第一行为一个整数N,(N <= 100000).接下来的N行,每行包括2个整数a b(1 <= a <= b <= N)。
当N = 0,输入结束。
 
Output
每个测试实例输出一行,包括N个整数,第I个数代表第I个气球总共被涂色的次数。
 
Sample Input
3
1 1
2 2
3 3
3
1 1
1 2
1 3
0
Sample Output
1 1 1
3 2 1

模板题,没什么好说的,搜了一下这题看见大家都是用树状数组做的,有空学一下。

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <algorithm>
  6. #define N 1000010
  7. using namespace std;
  8. struct node
  9. {
  10. int l,r,lz,w;
  11. } q[*N];
  12. int n;
  13. void pushdown(int rt)
  14. {
  15. if(q[rt].lz)
  16. {
  17. q[rt<<].lz+=q[rt].lz;
  18. q[rt<<|].lz+=q[rt].lz;
  19. q[rt<<].w+=q[rt].lz;
  20. q[rt<<|].w+=q[rt].lz;
  21. q[rt].lz=;
  22. }
  23. }
  24. void build(int l,int r,int rt)
  25. {
  26. q[rt].l=l;
  27. q[rt].r=r;
  28. q[rt].w=;
  29. q[rt].lz=;
  30. if(l==r)
  31. return ;
  32. int mid=(l+r)>>;
  33. build(l,mid,rt<<);
  34. build(mid+,r,rt<<|);
  35. return ;
  36. }
  37. void update(int lf,int rf,int l,int r,int rt)
  38. {
  39. if(lf<=l&&rf>=r)
  40. {
  41. q[rt].w+=;
  42. q[rt].lz+=;
  43. return ;
  44. }
  45. pushdown(rt);
  46. int mid=(l+r)>>;
  47. if(lf<=mid) update(lf,rf,l,mid,rt<<);
  48. if(rf>mid) update(lf,rf,mid+,r,rt<<|);
  49. }
  50. void query(int l,int r,int rt)
  51. {
  52. if(l==r)
  53. {
  54. if(l==)
  55. printf("%d",q[rt].w);
  56. else printf(" %d",q[rt].w);
  57. return ;
  58. }
  59. pushdown(rt);
  60. int mid=(l+r)>>;
  61. query(l,mid,rt<<);
  62. query(mid+,r,rt<<|);
  63. return ;
  64. }
  65. int main()
  66. {
  67. int s1,s2;
  68. while(scanf("%d",&n)!=EOF&&n!=)
  69. {
  70. build(,n,);
  71. for(int i=; i<n; i++)
  72. {
  73. scanf("%d%d",&s1,&s2);
  74. update(s1,s2,,n,);
  75. }
  76. query(,n,);
  77. printf("\n");
  78. }
  79. }

HDU1556:Color the ball(简单的线段树区域更新)的更多相关文章

  1. hdu1556 Color the ball 简单线段树

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 简单的线段树的应用 直接贴代码了: 代码: #include<iostream> # ...

  2. Color the ball HDU - 1556 (线段树)

    思路:线段树,区间更新 #include<iostream> #include<vector> #include<string> #include<cmath ...

  3. HDU5023:A Corrupt Mayor's Performance Art(线段树区域更新+二进制)

    http://acm.hdu.edu.cn/showproblem.php?pid=5023 Problem Description Corrupt governors always find way ...

  4. HDU1698:Just a Hook(线段树区域更新模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1698 Problem Description In the game of DotA, Pudge’s meat ...

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

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

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

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

  7. HDU1556 Color the ball & 牛客 contest 135-I 区间 [差分标记]

    一.差分标记介绍 差分标记用来解决针对区间(修改-查询)的问题,复杂度比线段树要更低.推荐这个博客. 例如,给数组中处于某个区间的数进行加减操作,然后查询某个位置上数的变化值. 二.HDU1556 C ...

  8. 【arc073e】Ball Coloring(线段树,贪心)

    [arc073e]Ball Coloring(线段树,贪心) 题面 AtCoder 洛谷 题解 大型翻车现场,菊队完美压中男神的模拟题 首先钦定全局最小值为红色,剩下的袋子按照其中较大值排序. 枚举前 ...

  9. ZOJ 1610 Count the Color(线段树区间更新)

    描述Painting some colored segments on a line, some previously painted segments may be covered by some ...

随机推荐

  1. fireworks切图

    下载安装完成后打开软件 打开一张图片 首选参数的撤销次数改成999 按住空格键 鼠标会变成小手的形状 这时候可以拖拽图像 找到切片工具 记住缩放比例的快捷键 ctrl+空格 放大某个区域 切的时候按住 ...

  2. Maven War包 POM配置文件

    如何为你的Web程序(war包设定配置文件) 约定 http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering ...

  3. Socket无连接简单实例

    使用无连接的套接字,我们能够在自我包含的数据包里发送消息,采用独立的读函数读取消息,读取的消息是使用独立的发送函数发送的.但是UDP数据包不能保证可靠传输,存在许多的因素,比如网络繁忙等等,都有可能阻 ...

  4. Oracle Apex 有用笔记系列 2 - 文件上传管理

    1. 页面设计 页面A有若干region, 当中一个region用于文件列表管理(包含显示,下载.删除).如图A. 在页面A有一button,点击它会调用页面B,页面B负责文件上传.如图B. 图A 图 ...

  5. NodeJS-003-自动刷新

    修改index.js之后,发现刷新浏览器,没有任何更改,需要关闭应用重新启动. 为了避免每次修改代码后要自动重启.通过安装supervisor来监控代码修改. 安装:npm install -g su ...

  6. complex()

    complex() 用于将一个对象转换为复数 In [1]: complex(123) # 将整数转换为复数 Out[1]: (123+0j) In [2]: complex(') # 将纯数字的字符 ...

  7. 如何连接 MySQL

    操作如下: [root@localhost ~]$ mysql -uroot -p' # 本地连接 MySQL 服务 [root@localhost ~]$ mysql -uroot -p' -h19 ...

  8. CentOS5.5环境下布署LVS+keepalived

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://kerry.blog.51cto.com/172631/401253 #!/bin ...

  9. Effective C++ —— 构造/析构/赋值运算(二)

    条款05 : 了解C++默默编写并调用哪些函数 编译器可以暗自为class创建default构造函数.copy构造函数.copy assignment操作符,以及析构函数. 1. default构造函 ...

  10. MQTT的学习研究(四)moquette-mqtt 的使用之mqtt Blocking API客户端订阅并接收主题信息

    在上面两篇关于mqtt的broker的启动和mqtt的服务端发布主题信息之后,我们客户端需要订阅相关的信息并接收相关的主题信息. package com.etrip.mqtt; import java ...