#PS0000249. Sơn chuồng bò (Painting the Barn)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Sơn chuồng bò (Painting the Barn)
Painting the Barn
Source: USACO
Version: Phuoc Hung OJ Extended
Problem Statement
Farmer John paints one side of his barn, represented by a coordinate plane. In each of painting operations, one coat is applied to an axis-aligned rectangle with lower-left corner and upper-right corner . Initially there are no coats. Find the area covered by exactly coats after all operations. Repeated rectangles count separately; boundaries have zero area.
Input
First line: integers . Each of the next lines contains four integers for one painting operation.
Output
Print one integer: the area covered by exactly coats.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; .
Example 1
Input
3 2
1 1 5 5
4 4 7 6
3 3 8 7
Output
8
Explanation
Pairwise intersections have areas 1, 4 and 6, and the triple intersection has area 1. Exactly two coats cover area 1+4+6−3=8.
Example 2
Input
2 1
0 0 2 1
2 0 4 1
Output
4
Explanation
The rectangles touch only along an edge. Each has area 2; exactly one coat covers area 4.