#P5927. Obstacle-Free Rectangles Game
Obstacle-Free Rectangles Game
Obstacle-Free Rectangles Game
Two players, A and B, play a game on a $1000000\times1000000$ grid. The grid points are given as $(x,y)$ with $(0,0)$ representing the bottom-left corner. They take turns placing a chess piece on an intersection point with the restriction that no two pieces share the same $x$ coordinate or the same $y$ coordinate.
After each move, the board automatically computes the number of obstacle-free rectangles defined by any two distinct chess pieces. Given two pieces with coordinates $(x_1,y_1)$ and $(x_2,y_2)$ (where $x_1\neq x_2$ and $y_1\neq y_2$), they define a rectangle with corners at $(\min(x_1,x_2),\min(y_1,y_2))$ and $(\max(x_1,x_2),\max(y_1,y_2))$. This rectangle is called obstacle-free if no other chess piece lies strictly inside the rectangle (i.e. no piece with coordinates $(x,y)$ satisfying $\min(x_1,x_2) < x < \max(x_1,x_2)$ and $\min(y_1,y_2) < y < \max(y_1,y_2)$).
When a new piece is placed, the score for that move is defined as the total number of obstacle-free rectangles (formed by any pair of pieces from the current board configuration). Each player's final score is the sum of the scores obtained from all of his/her moves.
Your task is to compute the cumulative total scores for players A and B given the sequence of moves.
inputFormat
The first line contains an integer $N$ ($N\ge3$) denoting the number of moves. Each of the next $N$ lines contains two integers $x$ and $y$, representing the coordinates where a chess piece is placed. The moves are given in order; the first move is made by player A, the second by player B, and so on.
outputFormat
Output two integers separated by a space: the total score of player A and the total score of player B.
sample
3
1 1
2 3
4 2
3 1