#P11048. [蓝桥杯 2024 省 Java B] 拼十字

    ID: 12400 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>树形数据结构树状数组2024蓝桥杯省赛

[蓝桥杯 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 NN rectangles. For the ii-th rectangle, its length and width are lil_i and wiw_i, and its color cic_i is one of red (0)(0), yellow (1)(1), or blue (2)(2). Now Xiaolan wants to know how many pairs among these NN rectangles can “build a cross”.

Two rectangles can “build a cross” if and only if:

  1. The two rectangles have different colors.
  2. Rectangle 11 has a strictly greater length than rectangle 22, and rectangle 11 has a strictly smaller width than rectangle 22.

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 NN, meaning there are NN rectangles.

The next NN lines each contain three integers ll, ww, and cc, 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 109+710^9 + 7.

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 22.

[Constraints]

  • For 30%30\% of the testdata: 1N50001 \leq N \leq 5000.
  • For 100%100\% of the testdata: 1N1051 \leq N \leq 10^5, 1l,w1051 \leq l,w \leq 10^5, 0c20 \leq c \leq 2.

Translated by ChatGPT 5