Can you help me with problem? Given N <= 10^5 pairs of points, suppose they are written in
array A, A[i][0] <= A[i][1]. Also, given M <= 10^5 pairs of segments, i-th pair given in form L_1[i], R_1[i], L_2[i], R_2[i]. For each pair of segments I need to find number of pairs from array A, such that for each pair (A[z][0], A[z][1]) it should be L_1[i] <= A[z][0] <= R_1[i] <= L_2[i] <= A[z][1] <= R_2[i].
I think here we can use scan line algorithm, but I don't know how to fit in time and memory. My idea works in N * M * log(N).
Task about pairs of points and segments
129 Views Asked by master At
1
There are 1 best solutions below
Related Questions in ALGORITHM
- Two different numbers in an array which their sum equals to a given value
- Given two arrays of positive numbers, re-arrange them to form a resulting array, resulting array contains the elements in the same given sequence
- Time complexity of the algorithm?
- Find a MST in O(V+E) Time in a Graph
- Why k and l for LSH used for approximate nearest neighbours?
- How to count the number of ways of choosing of k equal substrings from a List L(the list of All Substrings)
- Issues with reversing the linkedlist
- Finding first non-repeating number in integer array
- Finding average of an array
- How to check for duplicates with less time in a list over 9000 elements by python
- How to pick a number based on probability?
- Insertion Sort help in javascript -- Khan Academy
- Developing a Checkers (Draughts) engine, how to begin?
- Can Bellman-Ford algorithm be used to find shorthest path on a graph with only positive edges?
- What is the function for the KMP Failure Algorithm?
Related Questions in POINT
- Check if Rectangle is between two points
- ST_SetSRID ST_Point PostGIS giving strange output
- How do I enter an "empty" POINT() geometry value into a MySQL field of type POINT?
- unity camera should rotate around static point
- Optical Mark Recognition using C#
- point evaluation of NURBS curve given an axial coordinate
- Detect square in a List of Points
- SendMessage with Point not working
- How to index a list of points for faster searches of nearby points?
- Point cloud XYZ format specification
- How to get points of a GPX file by using GPX parser in java?
- Attempt to invoke interface method 'boolean java.util.Set.addAll(java.util.Collection)' on a null object reference
- GeoDjango saving Point geometry from form
- Looking for c / c++ library to generate a PointCloud ot an Depth Image / Ranged Map
- How to find a point lies inside the plane in 3d
Related Questions in SEGMENT
- add segment before controller without changing base url
- How to make a definition function to find particular symbols
- Is "memory segment" an intel-only concept in assembly programming?
- Segment framework make UIAlertController to crash with NSInternalInconsistencyException
- meteor iron router dynamic segment not working
- Why empty cells are printed in this code?_Python
- Can't add a section in FASM Syntax
- How to apply a function (some processing steps) only on a specific part of an image in MATLAB?
- BeanIO 2.1 Wrapped Segments
- Pushing segment registers on the stack for far calls
- Chart issue when using it inside a segment on Ionic2 project
- Plot geom_segment on geom_rect background
- What happens if a process calls out to code belonging to another process?
- Is segment-offset method common to all x86 chips or just 8086?
- Assembly: Using the Data Segment Register (DS)
Related Questions in SCANLINE
- Fast way of swapping Red/Blue bytes using ScanLine
- c++ opengl scan line algorithm
- Scanline Algorithm
- Inverting a bitmap in Embarcadero C++Builder
- ScanLine flood fill Thread 1: EXC_BAD_ACCESS (code=1, address=0x10b48427c)
- scanline function in qimage class
- delphi to lazarus - scanline
- PHP shell_exec() Behaves Differently Than Terminal Command Line MacOS
- Algorithm: Create rooftop with maximum height
- getting image color information from both RGB32 and indexed type images
- OpenGL scanline algorithm - does it use rays and bounding boxes?
- Task about pairs of points and segments
- Scanline algorithm: how to calculate intersection points
- scanline: finding intersection points
- Implementing a scanline algorithm
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
If you map A[i] to a point (A[i][0], A[i][1]) on 2d-plane, then for each segment, basically you're just counting the number of points inside the rectangle whose left-bottom corner is (L_1[i], L_2[i]) and right-top corner is (R_1[i], R_2[i]). Counting the points on 2d-plane is a classic question which could be solved in O(n logn). Here are some possible implementations:
Notice that number of points in a rectangle
P(l,b,r,t)could be interpreted asP(0,0,r,t)-P(0,0,l-1,t)-P(0,0,r,b-1)+P(0,0,l-1,b-1), so the problem can be simplified to calculatingP(0,0,?,?). This could be done easily if we maintain a fenwick tree during the process which basically resembles scan line algorithm.Build a persistent segment tree for each x-coordinate (in time O(n logn)) and calculate the answers for segments (in time O(m logn)).
Build a kd-tree and answer each query in O(sqrt(n)) time. This is not efficient but could be useful when you want to insert points and count points online.
Sorry for my poor English. Feel free to point out my typos and mistakes.