[USACO 2007 Ope S]City Horizon
题号:NC25078
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 32 M,其他语言64 M
64bit IO Format: %lld

题目描述

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.

输入描述:

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

输出描述:

Line 1: The total area, in square units, of the silhouettes formed by all N buildings
示例1

输入

复制
4
2 5 1
9 10 4
6 8 2
4 6 3

输出

复制
16

说明

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*1=16.