D - 1D Coulomb Editorial by evima
Let’s find the distance from each ball with a positive charge to the corresponding ball with a negative charge, and calculate the sum of those distances. From here on, balls with positive (or negative) charges are simply called positive (or negative) charges.
Consider the polygonal line graph of the cumulative sum of charges from the left at positions \(x=0.5, 1.5, \ldots , 2N+0.5\) on the number line, and let \(\mathrm{pot}(x)\) denote this value. For example, the graph for \(s=\) ++---+
is shown in the figure below. Since the total charge is \(0\), the term
\(-\) \((\) the sum of the charges of the ball strictly to the right of itself \()\)
in the formula for \(F\) is equal to the sum of the charges of the ball to the right of itself, including itself. Therefore, for a ball at \(x=i\),
\(F=(\mathrm{pot}(i-0.5)+\mathrm{pot}(i+0.5))\times(\) its own charge \()\).
In the end, it can be seen that in the region where the cumulative sum is positive, positive charges move to the right and negative charges move to the left, and vice versa in the region where it is negative (as indicated by the arrows in the figure). Therefore, charges with the same value of \((\mathrm{pot}(i-0.5)+\mathrm{pot}(i+0.5))\) pair up in the manner of a stack.
When adding a positive charge to the stack, consider the contribution to the distances between the corresponding charges. When a positive charge is added when \(k\) positive charges remain in the stack,
- The charge itself pairs up with a negative charge at a distance of at least \(1\).
- For the \(k\) existing charges, the positions of the charges to be paired up are moved away by the positive charge just added and the corresponding negative charge, so each distance increases by \(2\).
Therefore, there is a contribution of \(2k+1\) to the total distance. When a negative charge is placed (when positive charges remain), the distance to the corresponding positive charge on top is determined, and that charge is removed from the stack.
Therefore, if you know the excess of the number of positive (or negative) charges over the number of opposite charges at each point, you can calculate the contribution of the charge placed at that point. This can be solved by DP where, for example, the numbers of positive and negative charges placed so far are used as indices.
(Modified the first draft written by GPT-4.)
posted:
last update: