Hello, Codeforces!
It has come to my mind that a problem I authored, "The Struggle", despite having appeared in the HDU Multiuniversity Training (where there are ~1000 3 people teams), the Ptz Summer Camp and the Open Cup, I know of few (possibly no more than 5) people who have learned and independently implemented the solution.
The problem is pretty much fun and the solution is quite easy to implement (actual implementation < 2kb). In order to make a new advertisement for the problem and to spread the trick of the problem, I think it will be a good idea for me to written a good tutorial for the problem. So here it is!
The problem
The algorithm complexity of this question is $$$O(n \log n)$$$, where $$$n = \max_{(x,y) \in E} \max(x,y)$$$. Consider using the FWT algorithm for calculation. We consider xor convolution which can only process one at a time a$[x\times2^n,x\times2^n+2^n-1] \times [y\times2^n,y\times2^n+2 ^n-1]$ square. We first process all the largest squares that are all inside the ellipse, and then process the next largest squares, and so on...
But the complexity of this algorithm is $$$O(n \log^2 n)$$$, which is not fast enough. Consider optimizing this algorithm. The method is to perform FWT from the bottom up, and calculate the squares that need to be calculated at each layer. After calculating the inner product of FWT array, we should not calculate the inverse FWT, but should "accumulate" it on the result array. (See author's solution for better understanding)
One issue in the complexity analysis of this question is to prove that the sum of the side lengths of all squares is $$$O(n \log n)$$$. This fact can be proved on the condition that the border function is a monotone function, and the boundary of the ellipse can be split into four monotone functions. The idea of the proof is to see that the y-intervals corresponding to each x-interval must be a constant plus some "extra" intervals, and for x-coordinate intervals of the same size, the total length of the "extra y-intervals" cannot exceed $$$n$$$. Since there is only $$$\log n$$$ sizes for x-intervals, the proof is done.