Editorial for COCI '07 Contest 3 #4 Dejavu


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Suppose we choose the point P in which the angle is 90 degrees. Because the legs of the triangle must be parallel to the coordinate axes, then one of the other two points must have the same x-coordinate as P, and the other must have the same y-coordinate. The exact number of triangles is [freq_x(x_P)-1] \cdot [freq_y(y_P)-1].

Because the limit is low enough, we can pre-calculate freq_x and freq_y for each x and y in two arrays. The time complexity of the algorithm is \mathcal O(N+K), where K is the limit on the coordinates.


Comments

There are no comments at the moment.