City Horizon
Time Limit: 2000MS |
|
Memory Limit: 65536K |
Total Submissions: 18646 |
|
Accepted: 5145 |
Description
Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at the city horizon and observe the beautiful silhouettes formed by the rectangular buildings.
The entire horizon is represented by a number line with N (1 ≤ N ≤ 40,000) buildings. Building i's silhouette has a base that spans locations Ai through Bi along the horizon (1 ≤ Ai < Bi ≤ 1,000,000,000) and has height Hi (1 ≤ Hi ≤ 1,000,000,000). Determine the area, in square units, of the aggregate silhouette formed by all N buildings.
Input
Line 1: A single integer:
N
Lines 2..
N+1: Input line
i+1 describes building
i with three space-separated integers:
Ai,
Bi, and
Hi
Output
Line 1: The total area, in square units, of the silhouettes formed by all
N buildings
Sample Input
4
2 5 1
9 10 4
6 8 2
4 6 3
Sample Output
16
Hint
The first building overlaps with the fourth building for an area of 1 square unit, so the total area is just 3*1 + 1*4 + 2*2 + 2*3 - 1 = 16.
//坐标 x离散化 离散后求相邻两点的最大值h 接着对应原始的x坐标求面积 这里需要注意离散化卡map 所以可以利用二分查找 还有由于更新会导致左右两个坐标都被覆盖,所以离散化时可以 1 3 5 7。。。这样离散 每次求2 4 6 8的值即可
#include
#include
#include