Given an grid with trees (*) and empty cells (.), answer queries: how many trees in rectangle ? This is 2D range sum on a static grid. Options:
2D prefix sums: build, query
2D Sparse Table for sum: doesn't work (sum not idempotent) For counting, 2D prefix sums is the right choice. But if the query was "what's the maximum value in this rectangle?", 2D sparse table would apply. Constraints: up to , up to .