You are given a list of 2-D data points (nodes) and a list of query x-coordinates. Build a piecewise linear interpolator that, for each query, returns the interpolated (or extrapolated) y-value. If several nodes share the same x-coordinate, first average their y-values so that every x is unique. After this preprocessing, sort the nodes by x. For a query x_q:
If x_q is exactly equal to one of the node x’s, return the corresponding averaged y.
If x_q lies between two nodes, use the straight-line segment between them to interpolate.
If x_q is smaller than the smallest x (or larger than the largest x), use the leftmost (or rightmost) two nodes to extrapolate linearly.
Implement the function that performs these steps for every query and returns the list of resulting y-values.