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
- MCNP 6 - Doubts about cells
- Given partially sorted array of type x<y => first apperance of x comes before first of y, sort in average O(n)
- What is the algorithm behind math.gcd and why it is faster Euclidean algorithm?
- Purpose of last 2 while loops in the merge algorithm of merge sort sorting technique
- Dots and Boxes with apha-beta pruning
- What is the average and worst-case time complexity of my string searching algorithm?
- Building a School Schedule Generator
- TC problem 5-2:how to calculate the probability of the indicator random variable?
- LCA of a binary tree implemented in Python
- Identify the checksum algorithm
- Algorithm for finding a subset of nodes in a weighted connected graph such that the distance between any pair nodes are under a postive number?
- Creating an efficent and time-saving algorithm to find difference between greater than and lesser than combination
- Algorithm to find neighbours of point by distance with no repeats
- Asking code suggestions about data structure and algorithm
- Heap sort with multithreading
Related Questions in POINT
- fabric.js reset polygon bounding box after a point is moved
- Having different shapes of points for each line and making them shown on the legends
- WordPress database error Illegal mix of collations utf8mb3_general_ci,IMPLICIT and utf8mb4_unicode_520_ci,COERCIBLE
- FlxRect.getRotatedBounds not getting hitboxes correctly?
- How to generate lines with specific direction from points
- Chart.js coloring the shape in a chart
- Chart. js shape coloring
- How to extract reflectance values from points within a many image tiles to build a SVM model that can classify each tile using a fields classes
- How do I add the fifth point to chart.js?
- plot numbers on a map from an sf object
- I need help covering the edge cases of a ray casting algorithm on a simple 2d array
- Overlay in Python is not working when I try to combine two plots
- Finding a 90 degree angle in robodk path and creating two 90 degree vectors at found point
- vuforia area target point clound
- python loyalt point expire date calculation
Related Questions in SEGMENT
- Use dataparallel but only one GPU is used
- Customize Segment linkTool Handles in JointJs
- How to add userId info to Track call in Segment.Analytics.CSharp 2.3.3?
- How can I implement analytics.js to my page and send the tracking methods to my own backend
- Why does R's predict segmented package not include effect of other covariates?
- How to make a swipeable segmented control with custom view in SwiftUI?
- Segment Consent Manager Doesnt set cookies auto when shouldRequireConsent prop is false
- OpenSSL3.1 C example of AES-XTS using EVP interfaces Unable to segment data for calculation
- React Native always read UIApplicationLaunchOptionsURLKey with null
- Get the segment number
- Why do "segmented" and "selgmented" functions in the package "segmented" give different outputs?
- Using lazy_static! the size of the defined variable in the symbol table is 0
- Flutter Segment: Merge events for single user
- Issue with Segment Creation via Mailchimp API
- Greenplum Database: Segment data directory does not exist
Related Questions in SCANLINE
- Fast crop .png images in Delphi
- How can I remove horizontal line glitches from an image?
- Task about pairs of points and segments
- Inverting a bitmap in Embarcadero C++Builder
- Can scanline flood-fill optimization be extended to 3D?
- How to get scanlines over background image in CSS
- How to flood fill with Color of pattern image in swift?
- How can I get the whole polygon colored from this code?
- ScanLine flood fill Thread 1: EXC_BAD_ACCESS (code=1, address=0x10b48427c)
- PHP shell_exec() Behaves Differently Than Terminal Command Line MacOS
- Implementing a scanline algorithm
- How does this "common idiom" actually work?
- Simultaneous Ellipse Scan Conversion
- delphi Undeclared identifier: 'scanline'
- Scanline algorithm: calculate x of edges
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 # Hahtags
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.