This repository has been archived on 2022-06-22. You can view files and clone it, but cannot push or open issues or pull requests.
usaco-guide/content/6_Plat/2DRQ.md
2020-06-17 15:18:07 -07:00

3.3 KiB

id title author prerequisites
2DRQ 2D Range Queries Benjamin Qi
Platinum - 1D Range Queries

Extending Range Queries to 2D (and beyond).

See my implementations.

Static Array Queries

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).

You can extend the 1D BIT solution for range update + range query (mentioned in 1DRQ) to higher dimensions as well (USACO Camp - "Cows Play Global Thermonuclear War").

Problems

2D Segment Tree

Note: no lazy propagation in 2D.

Short Description

  • CSES 28.2, 28.4
  • Segment Tree (or BIT) nested inside segment tree
  • use 2D offline BIT instead whenever possible (faster, lower memory)

Problems