3.3 KiB
3.3 KiB
id | title | author | prerequisites | description | |
---|---|---|---|---|---|
2DRQ | 2D Range Queries | Benjamin Qi |
|
Extending Range Queries to 2D (and beyond). |
See my implementations.
Static Array Queries
- Multi-Dimensional RMQ (retrograd)
- GP of Serbia 2020 B
2D BIT
Tutorials
- GFG 2D BIT
- TopCoder BIT
- Suppose that you want to update
N\approx 10^5
points with both coordinates in the range[1,N]
.- The 2D BITs mentioned above use
O(N^2)
memory, which is too much. - Can be reduced to
O(N\log^2N)
memory with unordered map, but this might also be too much (and too slow). - If you know the points to be updated beforehand then you can reduce to
O(N\log N)
memory (and no maps).
- The 2D BITs mentioned above use
You can extend the 1D BIT solution for range update range query to higher dimensions as well
- Paper
- USACO Camp - "Cows Play Global Thermonuclear War" (2D case)
Problems
- CSES Forest Queries II
- DMOJ Soriya's Programming Project
- intended complexity is
O(N\log^2 N)
- compressed 2D BIT
- rather difficult to pass within time and memory limits
- Make sure to use
\n
instead ofendl
!
- Make sure to use
- thecodingwizard's implementation with Benq's 2d offline bit
- rather difficult to pass within time and memory limits
- or do divide & conquer with a 1D BIT
- same as first problem here
- thecodingwizard's (messy) implementation based off of article above
- intended complexity is
- IOI 2007 Pairs
- DMOJ Crowded Cities
- USACO Plat Friendcross
- USACO Plat Mowing
2D Segment Tree
Note: no lazy propagation in 2D.
Short Description
- CSES 28.2 (Sparse Segment Tree), 28.4
- Segment Tree (or BIT) nested inside segment tree
- use 2D offline BIT instead whenever possible (faster, lower memory)