#PS0000213. Đồng cỏ hình chữ nhật (Rectangular Pasture)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đồng cỏ hình chữ nhật (Rectangular Pasture)
Rectangular Pasture
Source: USACO
Version: Phuoc Hung OJ Extended
Problem Statement
There are cows at integer grid cells . All x-coordinates are distinct, and all y-coordinates are distinct. A rectangular region of cells with sides parallel to the axes encloses a subset of cows, including cows in boundary cells. Count the distinct subsets that can be enclosed. Different rectangles enclosing the same cows count only once. Include the empty subset.
Input
The first line contains . Each of the next lines contains two integers .
Output
Print the number of distinct subsets, including the empty subset. The result fits in a signed 64-bit integer.
Subtasks
- Subtask 1 (10 points): ; ; all x-coordinates are distinct and all y-coordinates are distinct.
- Subtask 2 (15 points): ; ; all x-coordinates are distinct and all y-coordinates are distinct.
- Subtask 3 (30 points): ; ; all x-coordinates are distinct and all y-coordinates are distinct.
- Subtask 4 (45 points): ; ; all x-coordinates are distinct and all y-coordinates are distinct.
Example 1
Input
4
0 2
1 0
2 3
3 5
Output
13
Explanation
Of the 16 subsets, {1,2,4}, {2,4}, and {1,4} cannot be isolated: their bounding rectangles also contain cow 3. The other 13 are feasible.
Example 2
Input
3
10 10
30 30
20 20
Output
7
Explanation
In x-order, every feasible nonempty subset is contiguous. There are 3 singletons, 2 pairs, 1 triple, and the empty subset.