#P7149. [USACO20DEC] Rectangular Pasture S
[USACO20DEC] Rectangular Pasture S
Description
Farmer John’s largest pasture can be viewed as a huge two-dimensional grid made of square cells (imagine a huge chessboard). Now, there are cows occupying some of the cells ().
Farmer John wants to build a fence that encloses a rectangular region; this rectangle must have its four sides parallel to the -axis and the -axis, and it must contain at least one cell. Please help him compute the number of different subsets of cows that he can enclose in such a region. Note that the empty set should be counted as one of the answers.
Input Format
The first line of input contains an integer . The next lines each contain two space-separated integers, indicating the coordinates of the cell occupied by a cow. All coordinates are distinct, and all coordinates are distinct. All values of and are in the range .
Output Format
Output the number of subsets of cows that FJ can enclose. It can be proven that this number fits in a 64-bit signed integer type (for example, long long in C/C++).
4
0 2
1 0
2 3
3 5
13
Hint
There are subsets in total. FJ cannot build a fence that encloses only cows , , and , or only cows and , or only cows and , so the answer is .
- Testdata 2-3 satisfy .
- Testdata 4-6 satisfy .
- Testdata 7-12 satisfy .
- Testdata 13-20 have no additional constraints.
Problem by: Benjamin Qi.
Translated by ChatGPT 5
京公网安备 11011102002149号