#P8261. Counting Valid Pairs
Counting Valid Pairs
Counting Valid Pairs
You are given n points, each point is given as \( (x_i, y_i, c_i) \) for \( i=1,2,\dots,n \). There are \( m \) queries. In each query, you are given three integers \( A, B, C \). For each query, count the number of unordered pairs \( (i,j) \) (with \( i<j \)) such that
\[ Ax_i + By_i + C < 0 \quad \text{and} \quad Ax_j + By_j + C < 0 \quad \text{and} \quad c_i = c_j. \]
Output the count for each query on a new line.
inputFormat
The first line contains two integers \( n \) and \( m \) separated by a space.
The next \( n \) lines each contain three integers \( x_i, y_i, c_i \) representing a point.
The following \( m \) lines each contain three integers \( A, B, C \) representing a query.
outputFormat
For each query, output a single integer representing the number of valid pairs. Each answer should be printed on its own line.
sample
3 2
1 2 1
-1 -2 1
0 0 2
1 1 -3
1 1 0
0
0
</p>