AreluF's blog

By AreluF, history, 4 years ago, In English

How to solve this problem?

Given n points in a plane and q queries in each query a point P is given, and for each query we have to find the minimum of the dot product of point P taken with the given n points.

1 <= n,q <= 10^5

0 <= |x|,|y| <= 10^9

  • Vote: I like it
  • +39
  • Vote: I do not like it

»
4 years ago, # |
  Vote: I like it +26 Vote: I do not like it

It can be solved with convex hull trick. For a fixed point, try to rearrange the formula to make it work.

  • »
    »
    4 years ago, # ^ |
    Rev. 2   Vote: I like it +10 Vote: I do not like it

    It looks to me like a 3D convex hull. How do you rearrange it?

»
4 years ago, # |
Rev. 2   Vote: I like it +18 Vote: I do not like it

First of all, we find lower convex envelope. Then we can run ternary search. It's the simplest way to do it. For max you would find upper convex envelope instead. If constraints would allow coordinates to be negative you would split points by their x(<0 and >=0) and do two queries.

Try problem squad from function cup 2019 it uses this concept but is a bit harder.

»
4 years ago, # |
Rev. 6   Vote: I like it +18 Vote: I do not like it

X1*x2+y1*y2=sqrt(x1^2+y1^2)*sqrt(x2^2+y2^2)*cos(a)

a is angle between vectors (x1, y1) and (x2, y2). |(x1,y1)|*|(x2,y2)| * cos(a) = (projectio)^2

This can be done with convex hull of dots and some binary search(lower hull for P.y>0 and upper hull for P.y<0)

P.s sorry for my poor english

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I know a trendy question on this concept. ;)

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +16 Vote: I do not like it

    It’s surprising how little the word “trendy” describes itself.