你可以浏览这个题解的中文版本。
The images are hosted on Github, use an accelerator if it fails to load.
Consider drawing the Huffman distance of three points.
Then we have , i.e. . This means that the slope of is and is on a line parallel to it.
We might as well enumerate , enumerate , and compute the number of legal by difference . Complexity with large constants.
Specifically, we enumerate and , and the problem translates into finding the number of on the four lines. It is sufficient to preprocess the prefix sum for each line with slope .
Note that to avoid double counting , it may be worthwhile to count the special endpoint positions separately.

