#P6774. Era's Tears

    ID: 19981 Type: Default 1000ms 256MiB

Era's Tears

Era's Tears

Little L loves discussing with the wise, and the wise often pose challenging puzzles. In this problem, we model the space-time as a 2D plane. An event is represented by a unique point \((x_i, y_i)\) on the plane, and an era is represented by an axis‐aligned rectangle.

For convenience, we define for two points \((a,b)\) and \((c,d)\) the relation \((a,b) \le (c,d)\) if and only if \(a \le c\) and \(b \le d\). Thus, an era given as a rectangle with bottom‐left \((r_{1}, c_{1})\) and top‐right \((r_{2}, c_{2})\) contains an event \((x,y)\) if and only if \((r_{1}, c_{1}) \le (x,y) \le (r_{2}, c_{2})\).

The regret is defined as follows: for any two events \(i\) and \(j\) (they are distinct) if either \((x_i, y_i) \le (x_j, y_j)\) or \((x_j, y_j) \le (x_i, y_i)\) holds, these two events form one regret. For a given era, the tears are the total number of regrets among all pairs of events contained in that era.

Your task is to compute the tears (i.e. the number of regrets) for each era.

inputFormat

The first line contains two integers \(n\) and \(m\) (the number of events and eras respectively). The following \(n\) lines each contain two integers representing an event's coordinates \(x_i\) and \(y_i\). The next \(m\) lines each contain four integers \(r_1\), \(c_1\), \(r_2\), and \(c_2\) which represent the bottom-left and top-right coordinates of the era's rectangle. It is guaranteed that \((r_1, c_1) \le (r_2, c_2)\) (i.e. \(r_1 \le r_2\) and \(c_1 \le c_2\)).

outputFormat

Output \(m\) lines, each line containing a single integer: the tears (i.e. the number of regrets) for the corresponding era.

sample

3 2
1 2
2 3
3 1
1 1 3 3
2 2 3 3
1

0

</p>