One day an excellent ACMer will leave the field to face new challenges, just like what the predecessors are doing.
Some of them have taken over their family businesses, and some of them are struggling with the edges of unemployment.
Some of them have the courage to display themselves and become a professional Ingress player, and some of them are still pushing themselves to limits and try to solve all problems in Project Euler.
But all these destinations are so shallow for Benecol de Cecco, the former king.
What he does now is to be the best respondents in StackOverflow.
StackOverflow is the largest, most trusted online community for developers to learn, share their programming knowledge, and build their careers.
Today, he notices a question which is posted by Kevin Li, saying:
Recently, I implemented an experiment where I need to find all the data records whose Euclidean distances to the query point $q$ are the same value $r$.
I tried to use the k-d tree to improve the search efficiency.
However, I found that the k-d tree needs to traverse all leaf nodes to return the result, that is, it still needs to compare all dataset to obtain the result.
This question can be formalized to build a database with real-time queries and modifications.
In the beginning, suppose we have $n$ different points in the plane.
The $i$-th point is located at $(x_i, y_i)$ and has a weight $w_i$.
Then we consider several queries and modifications dynamically given by
$1$ $x$ $y$ $w$, to insert a new point at $(x, y)$ of weight $w$, where we guarantee that before the operation no point was located in the place;
$2$ $x$ $y$, to delete the point located at $(x, y)$, where we guarantee that the point existed before the operation;
$3$ $x$ $y$ $k$ $w$, for each point whose Euclidean distance to $(x, y)$ is $\sqrt{k}$, to increase its weight by $w$;
$4$ $x$ $y$ $k$, to query the sum of weights for all points whose Euclidean distances to $(x, y)$ are $\sqrt{k}$.
Benecol de Cecco says this question is pretty easy and he asked me to share the problem with you all.
By the way, the Euclidean distance between two points $(x_0, y_0)$ and $(x_1, y_1)$ is equal to $\sqrt{(x_0 - x_1)^2 + (y_0 - y_1)^2}$.