[LA4108]SKYLINE

试题描述

The skyline of Singapore as viewed from the Marina Promenade (shown on the left) is one of the iconic scenes of Singapore. Country X would also like to create an iconic skyline, and it has put up a call for proposals. Each submitted proposal is a description of a proposed skyline and one of the metrics that country X will use to evaluate a proposed skyline is the amount of overlap in the proposed sky-line.

As the assistant to the chair of the skyline evaluation committee, you have been tasked with determining the amount of overlap in each proposal. Each proposal is a sequence of buildings, b1,b2,..., bn , where a building is specified by its left and right endpoint and its height. The buildings are specified in back to front order, in other words a building which appears later in the sequence appears in front of a building which appears earlier in the sequence.

The skyline formed by the first k buildings is the union of the rectangles of the first k buildings (see Figure 4). The overlap of a building, bi , is defined as the total horizontal length of the parts of bi , whose height is greater than or equal to the skyline behind it. This is equivalent to the total horizontal length of parts of the skyline behind bi which has a height that is less than or equal to hi , where hi is the height of building bi . You may assume that initially the skyline has height zero everywhere.

输入

The input consists of a line containing the number c of datasets, followed by c datasets, followed by a line containing the number `0'.

The first line of each dataset consists of a single positive integer, n (0 < n < 100000) , which is the number of buildings in the proposal. The following n lines of each dataset each contains a description of a single building. Thei -th line is a description of building bi . Each building bi is described by three positive integers, separated by spaces, namely, li , ri and hi , where li and rj (0 < li < ri100000) represents the left and right end point of the building and hi represents the height of the building.

输出

The output consists of one line for each dataset. The c -th line contains one single integer, representing the amount of overlap in the proposal for dataset c . You may assume that the amount of overlap for each dataset is at most 2000000.

Note: In this test case, the overlap of building b1 , b2 and b3 are 6, 4 and 4 respectively. Figure 4 shows how to compute the overlap of building b3 . The grey area represents the skyline formed by b1 and b2 and the black rectangle represents b3 . As shown in the figure, the length of the skyline covered by b3 is from position 3 to position 5 and from position 11 to position 13, therefore the overlap of b3 is 4.

输入示例

  1.  

输出示例

  1.  

数据规模及约定

见“输入

题解

为尊重原题面我就不翻译了。线段树打懒标记,记录一下区间最大最小值,小于最小值直接剪枝,大于等于最大值直接打懒标记并记录答案,否则下传标记接着递归处理。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <stack>
  6. #include <vector>
  7. #include <queue>
  8. #include <cstring>
  9. #include <string>
  10. #include <map>
  11. #include <set>
  12. using namespace std;
  13.  
  14. const int BufferSize = 1 << 16;
  15. char buffer[BufferSize], *Head, *Tail;
  16. inline char Getchar() {
  17. if(Head == Tail) {
  18. int l = fread(buffer, 1, BufferSize, stdin);
  19. Tail = (Head = buffer) + l;
  20. }
  21. return *Head++;
  22. }
  23. int read() {
  24. int x = 0, f = 1; char c = Getchar();
  25. while(!isdigit(c)){ if(c == '-') f = -1; c = Getchar(); }
  26. while(isdigit(c)){ x = x * 10 + c - '0'; c = Getchar(); }
  27. return x * f;
  28. }
  29.  
  30. #define maxn 100010
  31. int n, q, ans;
  32.  
  33. int maxv[maxn<<2], minv[maxn<<2], setv[maxn<<2];
  34. void build(int L, int R, int o) {
  35. maxv[o] = minv[o] = 0; setv[o] = -1;
  36. if(L == R) return ;
  37. int M = L + R >> 1, lc = o << 1, rc = lc | 1;
  38. build(L, M, lc); build(M+1, R, rc);
  39. return ;
  40. }
  41. void pushdown(int o) {
  42. int lc = o << 1, rc = lc | 1;
  43. if(setv[o] >= 0) {
  44. maxv[o] = minv[o] = setv[o];
  45. setv[lc] = setv[rc] = setv[o];
  46. setv[o] = -1;
  47. }
  48. return ;
  49. }
  50. int ql, qr;
  51. void update(int L, int R, int o, int h) {
  52. pushdown(o);
  53. if(minv[o] > h) return ;
  54. if(ql <= L && R <= qr && maxv[o] <= h) {
  55. maxv[o] = minv[o] = setv[o] = h;
  56. ans += (R - L + 1);
  57. return ;
  58. }
  59. int M = L + R >> 1, lc = o << 1, rc = lc | 1;
  60. if(ql <= M) update(L, M, lc, h);
  61. if(qr > M) update(M+1, R, rc, h);
  62. maxv[o] = max(maxv[lc], maxv[rc]);
  63. minv[o] = min(minv[lc], minv[rc]);
  64. return ;
  65. }
  66.  
  67. int main() {
  68. int T = read();
  69. while(T--) {
  70. q = read(); ans = 0;
  71. n = maxn - 10;
  72. build(1, n, 1);
  73. while(q--) {
  74. ql = read(); qr = read() - 1; int h = read();
  75. update(1, n, 1, h);
  76. }
  77. printf("%d\n", ans);
  78. }
  79.  
  80. return 0;
  81. }

[LA4108]SKYLINE的更多相关文章

  1. [LeetCode] The Skyline Problem 天际线问题

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  2. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  3. [LeetCode] The Skyline Problem

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  4. [地图SkyLine二次开发]框架(5)完结篇

    上节讲到,将菜单悬浮到地图上面,而且任何操作都不会让地图把菜单盖住. 这节带大家,具体开发一个简单的功能,来了进一步了解,这个框架. 1.想菜单中添加按钮 -上节定义的mainLayout.js文件里 ...

  5. [地图SkyLine二次开发]框架(2)

    上节讲到,地图加载. 但我们可以发现,当没有页面布局的情况下,<OBJECT>控件,没有占满整个屏幕,这里我们就要用到Extjs的功能了. 这节要讲的是用Extjs为<OBJECT& ...

  6. [地图SkyLine二次开发]框架(1)

    项目介绍: 项目是三维地理信息系统的开发,框架MVC4.0 + EF5.0 + Extjs4.2 + SkyLine + Arcgis,是对SkyLine的二次开发. 项目快结束了,先给大家看一眼效果 ...

  7. Java for LeetCode 218 The Skyline Problem【HARD】

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  8. The Skyline Problem

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  9. 218. The Skyline Problem *HARD* -- 矩形重叠

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

随机推荐

  1. windows API 开发飞机订票系统 图形化界面 (四)

    接下来的是录入航班.修改航班信息功能的实现: //录入航班 BOOL EntryFlight(HWND hEntryDlg){ TCHAR szDiscount[]; TCHAR szFare[],s ...

  2. Enum扩展及MVC中DropDownListFor扩展方法的使用

    public enum SearchState { /// <summary> /// 全部 /// </summary> [Description("全部" ...

  3. CNN 手写数字识别

    1. 知识点准备 在了解 CNN 网络神经之前有两个概念要理解,第一是二维图像上卷积的概念,第二是 pooling 的概念. a. 卷积 关于卷积的概念和细节可以参考这里,卷积运算有两个非常重要特性, ...

  4. 每天一个linux命令(19):Linux 目录结构

    对于每一个Linux学习者来说,了解Linux文件系统的目录结构,是学好Linux的至关重要的一步.,深入了解linux文件目录结构的标准和每个目录的详细功能,对于我们用好linux系统只管重要,下面 ...

  5. 英语etc怎么发音、单词来历

    etc是等等的意思,与and so on 相同 音标/et'set(a)ra/ 源于法语et cetera,也是等等的意思 在计算机操作系统目录(linux和windows)有一个叫etc的目录 里面 ...

  6. zabbix_监控_端口

        目的:监控web主机80端口是否在供提服务.如果不在发出报警.配置:    1.添加监控项(Items).        打开zabbix web管理界面:选择"Configurat ...

  7. 负margin一些奇葩的布局技巧

    copy_from_ http://www.hicss.net/i-know-you-do-not-know-the-negative-margin/ <!doctype html> &l ...

  8. Log4Net使用详解

    1.Log4Net环境的搭建与基本配置 (1)Log4Net框架介绍     Log4net 是 Apache 下一个开放源码的项目,它是Log4j 的一个克隆版.我们可以控制日志信息的输出目的地.L ...

  9. 利用getHibernateTemplate实现简单的操作

    package org.tarena.dao; import java.sql.SQLException; import java.util.List; import javax.annotation ...

  10. Eclipse启动Tomcat错误:Several ports (8005,8009) required by Tomcat v6.0 Server at localhost are already

    解决办法: 1.netstat -aon|findstr 8005 可查看指定端口号使用情况 2.tasklist |findstr 10452 找出占用指定进程Id的程序 3.taskkill /p ...