PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000251. Diện tích hợp hình chữ nhật (Rectangle Union Area)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Diện tích hợp hình chữ nhật (Rectangle Union Area)
Rectangle Union Area
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given axis-aligned rectangles , find the area covered by at least one rectangle. Count overlap only once; boundaries have zero area.
Input
First line: . Each of the next lines contains .
Output
Print one integer: the union area.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; .
Example 1
Input
2
0 0 3 2
2 1 5 4
Output
14
Explanation
Areas are 6 and 9, intersection is 1; union is 14.
Example 2
Input
3
0 0 2 2
2 0 4 2
0 0 2 2
Output
8
Explanation
First two rectangles touch along an edge; third repeats first. Total is 8.