title: how many line segments will intersect in a plane will intersect with a horizontal line ? what will be the most effective way to find this
body: <p>I’m trying to solve <a href="https://www.codechef.com/MARCH20A/problems/LAZER" rel="nofollow noreferrer">this Cyberchef challenge</a>:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>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.</p>
  
  <p>So this is the problem where:  </p>
  
  <ul>
  <li>2&lt;=N&lt;= 100000  </li>
  <li>1&lt;=Q&lt;= 100000</li>
  </ul>
  
  <p>Can anyone teach me what approach will be best and most effective in terms of time complexity?</p>