#P9996. Count Valid Point Pairs
Count Valid Point Pairs
Count Valid Point Pairs
Given n distinct points ( (x_i, y_i) ) and m queries, each query provides three integers ( A, B, C ). For each query, count the number of pairs ( (i, j) ), with ( i < j ), such that the following conditions are satisfied:
- ( x_i < x_j ) and ( y_i < y_j ).
- ( A x_i + B y_i + C > 0 ) and ( A x_j + B y_j + C > 0 ).
Input Format:
The first line contains two integers n and m separated by a space. The next n lines each contain two integers representing the coordinates ( x_i ) and ( y_i ) of the points. The following m lines each contain three integers ( A, B, C > for a query.
Output Format:
For each query, output a single integer on a new line representing the number of valid pairs ( (i, j) ) that satisfy the conditions.
inputFormat
The input begins with two integers n and m ( (1 \leq n, m \leq \text{small constraints}) ) on the first line.
Then follow n lines, each containing two integers ( x_i ) and ( y_i ), representing the coordinates of the points. All points are distinct.
Then m lines follow, each containing three integers ( A ), ( B ), and ( C ) representing a query.
outputFormat
For each query, output a single integer which is the number of pairs ( (i, j) ) (with ( i < j )) that satisfy the conditions ( x_i < x_j ), ( y_i < y_j ), ( A x_i + B y_i + C > 0 ), and ( A x_j + B y_j + C > 0 ). Each answer should be printed on a new line.
sample
3 1
1 2
2 3
3 4
1 1 -5
0