#P11048. [蓝桥杯 2024 省 Java B] 拼十字
[蓝桥杯 2024 省 Java B] 拼十字
Background
Note: For the original problem (Java), the time limit is 3.0 s and the memory limit is 512 MB.
Problem Description
In the mysterious ancient forest of LQ Kingdom, there is a mysterious ruin called “Build a Cross”. It is said that “Build a Cross” was built by an ancient civilization. It is a huge stone structure formed by stacking two large rectangles so that they cross each other, creating a solemn and mysterious cross shape.

Now you are given rectangles. For the -th rectangle, its length and width are and , and its color is one of red , yellow , or blue . Now Xiaolan wants to know how many pairs among these rectangles can “build a cross”.
Two rectangles can “build a cross” if and only if:
- The two rectangles have different colors.
- Rectangle has a strictly greater length than rectangle , and rectangle has a strictly smaller width than rectangle .
Note that the length and width of a rectangle are fixed and cannot be swapped by rotating the rectangle.
Input Format
The first line contains an integer , meaning there are rectangles.
The next lines each contain three integers , , and , representing the length, width, and color of a rectangle.
Output Format
Output one integer, the answer. Since the answer may be very large, output it modulo .
5
1 10 0
6 6 0
8 6 1
6 10 0
1 2 1
2
Hint
[Sample Explanation]
The 3rd rectangle can build a cross with the 1st rectangle, and the 3rd rectangle can also build a cross with the 4th rectangle. So there are 2 pairs of rectangles that can build a cross, and the answer is .
[Constraints]
- For of the testdata: .
- For of the testdata: , , .
Translated by ChatGPT 5