Количество пересечений отрезков линии ?
You are given N points in a plane (numbered 1 through N); for each valid i, the i-th point is Pi=(i,Ai). There are N−1 line segments between them (numbered 1 through N−1); for each valid i, the i-th line segment is formed by connecting the points Pi and Pi+1. You are given Q horizontal line segments . Each query horizontal line segment is denoted by two points, from a point (x1,y) to a point (x2,y) (where it stops and does not propagate further). For Every Horizontal line segment, you have to find the number of line segments from those (N-1 line segments) it collides with on the way. So this is the problem where : 2<=N<= 100000 !<=Q<= 100000 Can anyone teach me what approach will be best and most effective in terms of time complexity?
Что я уже пробовал:
Я не знаю, как к этому подступиться .Я подумал, что дерево КД может помочь.Но я не знаю, как использовать его для линейного сегмента.