/ WHOJ / 题库 /

[USACO07OPEN]City Horizon S

[USACO07OPEN]City Horizon S

描述

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.

约翰带着奶牛去都市观光。在落日的余晖里,他们看到了一幢接一幢的摩天高楼的轮廓在地平线上形成美丽的图案。以地平线为 \(X\) 轴,每幢高楼的轮廓是一个位于地平线上的矩形,彼此间可能有 重叠的部分。奶牛一共看到了 \(N\) 幢高楼,第 \(i\) 幢楼的高度是 \(H_i\),两条边界轮廓在地平线上的坐标是 \(A_i\) 到 \(B_i\)。请帮助奶牛们计算一下,所有摩天高楼的轮廓覆盖的总面积是多少。

简略题意,最好不要点,不过点了也没逝

格式

输入格式

第一行一个整数\(N\),然后有\(N\)行,每行三个正整数\(a_i、b_i、H_i\)。

输出格式

一个数,数列中所有元素的和。

样例1

输入样例1

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

输出样例1

16

限制

\(N<=40000 , a、b、k<=10^9\) 。