#P6579. Dominating Pairs Count Query
Dominating Pairs Count Query
Dominating Pairs Count Query
You are given a two-dimensional plane. For two points \( (x_1, y_1) \) and \( (x_2, y_2) \), we say that \( (x_1, y_1) \) is dominated by \( (x_2, y_2) \) (written as \( (x_1, y_1) \le (x_2, y_2) \)) if and only if \( x_1 \le x_2 \) and \( y_1 \le y_2 \).
Initially, you are given \( n \) distinct points \( \{(x_i,y_i)\}_{i=1}^{n} \). Then, you need to answer \( m \) queries. Each query provides two points \( (x, y) \) and \( (x', y') \). For each query, count the number of ordered pairs \( (i,j) \) (with \( i \neq j \)) such that
[ (x, y) \le (x_i,y_i) \le (x_j,y_j) \le (x',y') ]
Here, the inequalities are understood component-wise. Points that lie within the axis-aligned rectangle defined by \( (x,y) \) and \( (x', y') \) are considered. Your task is to count all pairs among these points which also satisfy the domination relation.
inputFormat
The first line contains two integers \( n \) and \( m \) denoting the number of points and the number of queries respectively.
The next \( n \) lines each contain two integers \( x_i \) and \( y_i \), representing the coordinates of the points.
The following \( m \) lines each contain four integers \( x, y, x', y' \), representing a query. In each query, you need to consider points \( (x_i,y_i) \) such that \( (x,y) \le (x_i,y_i) \le (x',y') \) (component-wise) and count the number of ordered pairs \( (i,j) \) (with \( i\neq j \)) satisfying \( (x_i,y_i) \le (x_j,y_j) \) component-wise.
outputFormat
For each query, output a single integer that represents the number of valid ordered pairs satisfying the conditions.
sample
4 2
1 2
2 3
3 4
4 5
1 2 3 4
2 3 4 5
3
3
</p>