[Original answer] how many segments each point is used
I'm not sure I understood the problem correctly, but it looks like a simple example of using a histogram ...
- create an array of counters (one element per point)
- set it to zero
processes the last line, increasing each used point counter O(m)
write the answer by reading the histogram O(n)
So the result should be O(m+n) something like (C ++):
const int n=2,m=3; const int p[n][2]={ {0,5},{7,10} }; const int s[m]={1,6,11}; int i,cnt[n]; for (i=0;i<n;i++) cnt[i]=0; for (i=0;i<m;i++) if ((s[i]>=0)&&(s[i]<n)) cnt[s[i]]++; for (i=0;i<n;i++) cout << cnt[i] << " ";
But since you can see that the p[] coordinates are never used, so either I missed something in the description of the problem, or you missed something, or there are only tricks.
[edit1] after resolving inconsistencies in OP, the result is slightly different
By the number of points in each segment:
- create an array of counters (one element per segment)
- set it to zero
- processes the last line, increasing each used point counter
O(m) - write the answer by reading the histogram
O(m)
So the result of O(m) is something like (C ++):
const int n=2,m=3; const int p[n][2]={ {0,5},{7,10} }; const int s[m]={1,6,11}; int i,cnt[m]; for (i=0;i<m;i++) cnt[i]=0; for (i=0;i<m;i++) if ((s[i]>=0)&&(s[i]<n)) cnt[i]++; for (i=0;i<m;i++) cout << cnt[i] << " ";
[Note]
After adding a new pattern to the OP, it is now clear that:
- indices start at
0 - the problem is how many points from the table
p[n] really used by each segment ( m exit numbers)